Python Twitch bot !addcom difficulties -


i making twitch bot using python because mirc started asking me pay, went simpler , free! current issue want make command (!addcom) moderators can add commands other users can use.

for example, !addcom !test test write !test test file or python file , !test , this test in chat. struggling find out way this, , have far:

def command_addcom():     file = open("test.txt", "w")     msg = input('')     file.write(msg)     file.close()     send_message(chan,'command added (testing)') 

unfortunately asks input in command prompt , doesn't @ all. love take text directly chat , place in file. sorry don't have code show, entire command stands! ahead of time.

i suggest save user defined command in python dict. instance, in example, be

command['!test'] = 'this test' 

and saving problem mention, suggest use json module it. save above command dict

with file('setting.json','w') settingfile     json.dump(command, settingfile) 

each time bot init, should load command dict actual json file

with file('setting.json','r') settingfile:     command = json.load(settingfile) 

so have user defined command dict in program


finally, @ parser of user message(here assume usermessage), should check if user command found in command dict. try

usercommand = usermessage.split(' ')[0] if command[usercommand]:     # sendmsg twicth irc     print command[usercommand] 

the official python document should give enough information how use json module, or maybe try configparser either.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -