forked from DesertBot/DesertBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Var.py
37 lines (28 loc) · 1.2 KB
/
Var.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Created on Mar 09, 2016
@author: StarlitGhost
"""
from twisted.plugin import IPlugin
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import BotCommand
from zope.interface import implementer
from desertbot.message import IRCMessage
from desertbot.response import IRCResponse, ResponseType
@implementer(IPlugin, IModule)
class Var(BotCommand):
def triggers(self):
return ['var']
def help(self, query):
return ("var <varname> <value>"
" - sets <varname> to <value>, which can be accessed later using $<varname>."
" the variables don't persist between messages,"
" so it is only useful as a support function for aliases using sub and/or chain")
def execute(self, message: IRCMessage):
if len(message.parameterList) < 1:
return IRCResponse(ResponseType.Say,
"You didn't give a variable name!",
message.replyTo)
varname = message.parameterList[0]
value = ' '.join(message.parameters.split(' ')[1:])
return IRCResponse(ResponseType.Say, "", message.replyTo, extraVars={varname: value})
var = Var()