Package: doclib
DocLibA chatbot library for euphoria.io.UsageInstallationTo install, usepiporpip3:pip3installdoclibWINDOWS USERS: YOU MUSTINSTALL WSLAND RUN THIS ON IT IN ORDER FOR IT TO WORKWhen beginning a new bot, import theBotclass:fromdoclibimportBotBasic BotsA basic bot will be aBotobject, constructed with anick(the bot's name, shown in the room), aroom(where the bot is sent by default, defaults to bots or test in debug mode), and anowner(your euphoria username.):sampleBot=Bot(nick='bugBot',room='test',owner='sample user')Constructor Optionsoptiondefaultusagenicknone, this is requiredThe nick the bot will enter the room with.room"bots"The default room for the bot to be sent to.owner"nobody"The owner/creator of the bot (you).passwordblank stringroom password (used for private rooms)help"[nick] is a bot made with Doctor Number Four's Python 3 bot library, DocLib (link: https://github.com/milovincent/DocLib) by @[owner].It follows botrulez and does not have a custom !help message yet."your custom !help command response. can also be set by adding a"^!help @[nick w/o spaces]$"command to your regexesping"Pong!"your custom !ping response.importantFalseifTrue, the bot will only be killable by a roomhost or the owner.NOT RECOMMENDED FOR SIMPLE BOTS OR BOTS PRONE TO SPAM.killed"/me has died"your custom message sent when bot is !killed.API_timeout10ADVANCED: number of API responses to check for command responses. You should not need to change this unless the room is particularly active.advancedFalseADVANCED: ifTrue, declares the bot as advanced, enabling the user to directly handle any API response (while still obeying botrulez)functionNoneADVANCED: specifies the universal advanced start handler function.customArgsFalseADVANCED: Removes the set of default command-line arguments for bots.sendableFalseIfTrue, enables the bot to be sent to other rooms with the !send @bot &room command.humanFalseIfTrue, the bot shows up in the People list. If used improperly, this is against Euphoria's ToS.killChildrenFalseIfTrue, when killed, the bot will kill any copies it has made as well.Once constructed, the user should assign a regex dictionary for non-advanced use cases:sampleBot.set_regexes({r'^!command$':function,r'(?i)word':'response',r'^!bunchamessages$':{"message":"nick to use","second message":"different nick"},r'^!afewmessages$':["first message","second message"]})Regex FormattingDocLib uses the default pythonrelibrary for regex formatting.Custom Function ResponsesResponses with a function value run the function with aBotobject (chatbot), anAttrDict(msg), and the regexmatchobject (matches). Functions can utilise any of the numerousBotmethods and all return the API's reply as anAttrDict:MethodParametersEffectsend_msgparent(AttrDictor string),msgString(string)SendsmsgStringas a reply toparent, whereparentcan either be a string containing the message id returned by the API or anAttrDictwith the structure of asend-replygenerated by the API (recommended: use themsgparameter given to your custom function)set_nicknick(string)Sets the bot's name tonickget_userlistnonereturns an array of userAttrDicts currently in the room, including bots, accounts, and agents.move_toroomName(string),password(string, default is an empty string)Moves the bot to a different room, specified byroomName, and, if necessary, attempts to log into it usingpassword.restartnoneRestarts the bot.killnoneKills the bot.copy_toroomName(string),password(string, default is an empty string)Creates a newBotobject set to appear in &roomNameand returns it. The user can then start it in a separate thread with thestart_in_new_threadfunction.initiate_pmid(string),bot(Bot, default None)Starts a PM with the userid, placingbotin said PM room if specified, else a copy of the bot receiving the command.loginemail(string),password(string)Logs bot in as a user. Takes effect on reconnect, and the bot will show up in the People list.To log errors and info, useBot.logwith amessagestring and the optionalerrorboolean. (note: NOT aBotsubfunction) To choose between a set of responses to a command randomly (including dictionaries, strings, and even functions), useBot.randomize_between(*responses).The regex string for any command may be replaced with a function that takes the relevantAttrDictmsgobject and returns a boolean (Trueto respond,Falseto continue).Example:Regex:sampleBot.set_regexes({'^!alive$':alive})Function (definedabove bot start)defalive(chatbot,msg,matches):chatbot.send_msg(parent=msg,msgString='/me IS ALIVE!')chatbot.set_nick('Thunder')chatbot.send_msg(parent=msg,msgString='/me crashes')chatbot.set_nick('sampleBot')Custom HandlersTo set custom function handlers for any API response (when notadvanced, this does not includeping-events,send-events,errors, orbounce-events), useset_handler:sampleBot.set_handler(eventString="join-event",on_join)orsampleBot.set_handlers({"joinEvent":on_join})All handler functions, including the universal function parameter for advanced start, are passed the API response (msg) as anAttrDictevery time the corresponding event is received. Custom handlers take precedence over advanced start's universal handler.StartupOnce the bot is set up and populated with commands, the user can connect and start it:sampleBot.connect()sampleBot.start()To start a bot in a new thread (useful for copies), use thestart_in_new_threadfunction instead:copy.connect()copy.start_in_new_thread()Advanced UsageUsing anadvancedvalue ofTrue(whether in the bot's declaration or its start function) enables the user to set a universal handler for all API events, in addition to any custom handlers:sampleBot.start(advanced=True,function=handler_function)If unspecified, advanced start uses a filler function that does nothing, enabling the user to use entirely custom handlers for every API response.Command Line OptionsWhen running any bot in the command line, the user has access to a few default options:optionusage-t,--test,--debugUsed to debug dev builds. Sends bot to &test instead of its default room.--room ROOM,-r ROOMSends bot to &ROOM instead of its default room.--password PASSWORD,-p PASSWORDPassword to use should the room be locked.To add new arguments, use the bot'sadd_command_line_argfunction as you would the default Pythonargparse.add_argumentfunction. It returns the value of the added argument if provided anameparameter. To remove the default arguments, setcustomArgsin theBotconstructor toTrue.