You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ HangoutsBot
4
4
Setup
5
5
--------------
6
6
7
-
In order to use this, you'll need to setup a GMail account for logging in, and a config.json file to give the bot its settings. The config file should look like:
7
+
In order to use this, you'll need to setup a GMail account for logging in, and a config.json file (placed either at the folder root or in the Core folder) to give the bot its settings. The config file should look something like:
8
8
9
9
```JSON
10
10
{
@@ -14,7 +14,7 @@ In order to use this, you'll need to setup a GMail account for logging in, and a
@@ -32,7 +32,9 @@ In order to use this, you'll need to setup a GMail account for logging in, and a
32
32
}
33
33
}
34
34
}
35
-
```
35
+
```
36
+
37
+
If you neglect to create a config.json file, this exact one will be created for you in the Core folder.
36
38
37
39
Line by Line breakdown (excluding braces/brackets):
38
40
@@ -54,6 +56,8 @@ Line by Line breakdown (excluding braces/brackets):
54
56
16. Start of the "forward_to" array. All conversation IDs listed here will have this conversation forwarded to them.
55
57
17. "CONV-ID-HERE" should be replaced with an actual id, which looks something like "Ugxxxxxxxxxxx_xxxxxxxxxxxxx", and then commands will be forwarded to that conversation.
56
58
59
+
Note: Every top-level argument can be made a conversation level argument, which will overwrite the top level argument for that conversation. For instance, if you put a commands_admin array containing only "quit" and "block" in "CONV-ID-HERE", in the CONV-ID-HERE conversation, all users would be able to run /hangouts, /reload, /config, etc but would still be blocked from running /quit and /block. Conversely, if you put an empty commands_admin array in CONV-ID-HERE, all users in that conversation would be able to run all commands (except any commands in the "commands_conversation_admin" array unless they're a conversation admin.)
60
+
57
61
A cookies.txt file will also be created, holding the cookies that are valid for your login.
58
62
59
63
Usage
@@ -72,19 +76,20 @@ Any function created in the ExtraCommands.py file (or any .py file that imports
72
76
73
77
```python
74
78
@DispatcherSingleton.register
75
-
deffunction_for_bot(bot, event, *args):
76
-
if''.join(args) =='?':
77
-
segments = [hangups.ChatMessageSegment('New Function For Bot', is_bold=True),
hangups.ChatMessageSegment('Purpose: Does a thing.')]
82
-
bot.send_message_segments(event.conv, segments)
83
-
else:
84
-
# Do actual functionality here.
79
+
defcommand(bot, event, *args):
80
+
"""Command
81
+
Usage: /command <required argument> <optional: optional argument> {for complicated commands, put an example call in curly braces}
82
+
Purpose: Does a thing."""
83
+
84
+
# Do actual functionality here.
85
85
```
86
86
87
-
It should be frowned upon to force a user to put underscores in to use a command, but that's up to you to decide.
87
+
The docstring isn't necessary, but should be used as it will be printed out if a user uses "/help \<command name\>" or does "/\<command_name\> ?". Admin-only commands generally don't have help text by default, but that's left up to your discretion.
88
+
89
+
The bot variable is a reference to the HangoutsBot that is currently running. The event variable is a ConversationEvent that has information about the event (as in, text, the user who sent it, the conversation, and all users in the conversation.) The \*args variable is a tuple of all of the text sent along with the command call, split by whitespace so that you can easily check its values. Look at the DefaultCommands.py file for actual examples of how commands work.
90
+
91
+
It should be frowned upon to force a user to put underscores in to use a command, but that's up to you to decide.
0 commit comments