-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti.py
135 lines (134 loc) · 5.15 KB
/
multi.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import hexchat
import time
__module_name__ = "multiload"
__module_version__ = "1.0"
__module_description__ = "a module to load/unload modules"
class nim:
def __init__(a):
a.nimmem = {}
#print a
def nimmove(s,a,b,c):
#print a
#print s.nimmem # uncomment to see memory
name = a[0]
if name in s.nimmem:
try:
go = int(a[3][1:])
tmp = s.nimmem[name]
tmp[0]+=s.test(go,tmp[2])
rgo = s.test(go,tmp[2])
if tmp[0] >= tmp[1]:
hexchat.command("msg "+name+" you've won nim, congratulations, we'll send the 1 million pounds when we get round to it (never)")
del s.nimmem[name]
else:
comgo=s.test((tmp[1]-tmp[0])%(tmp[2]+1),tmp[2])
tmp[0]+=comgo
hexchat.command("msg "+name+" you played "+str(rgo)+" and I played "+str(comgo)+" which brought the total to "+str(tmp[0]))
if tmp[0] >= tmp[1]:
hexchat.command("msg "+name+" i win nim and I get 1 million pounds, bye")
del s.nimmem[name]
else:
s.nimmem[name] = tmp
except:
hexchat.command("msg "+name+" go must be an interger")
else:
if a[3][1:] == "setfirst":
try:
s.nimmem[name] = a[4].split(",")
s.nimmem[name] = [0]+[int(s.nimmem[name][0])]+[int(s.nimmem[name][1])]
tmp=s.nimmem[name]
comgo=s.test((tmp[1]-tmp[0])%(tmp[2]+1),tmp[2])
tmp[0]+=comgo
hexchat.command("msg "+name+" I played "+str(comgo)+" which brought the total to "+str(tmp[0]))
if tmp[0] >= tmp[1]:
hexchat.command("msg "+name+" i win nim and I get 1 million pounds, bye")
del s.nimmem[name]
else:
s.nimmem[name] = tmp
except:
hexchat.command("msg "+name+" setup must be valid")
del s.nimmem[name]
elif a[3][1:] == "set":
try:
#print( a[4][1] )
s.nimmem[name] = a[4].split(",")
#print s.nimmem[name]
s.nimmem[name] = [0]+[int(s.nimmem[name][0])]+[int(s.nimmem[name][1])]
except:
hexchat.command("msg "+name+" setup must be valid")
del s.nimmem[name]
else:
hexchat.command("msg "+name+" welcome to the automated nim just privmsg me with a message in the format \"set 31(total limit),6(indlim)\" bye")
return hexchat.EAT_NONE
def test(s,a,b):
a-=1
a=a%b
a+=1
return a
def reply(a,b,c):
hexchat.command("msg "+(a[0].split("!")[0][1:])+" the time is "+ time.ctime())
#hexchat.command("msg "+(a[0].split("!")[0][1:])+" the time is 11:30")
hexchat.prnt((a[0].split("@"))[-1])
#hexchat.prnt(str(a)+str(b)+str(c))
return hexchat.EAT_NONE
def chanreply(a,b,c):
hexchat.command("msg #clock the time is "+ time.ctime())
#hexchat.command("msg #clock the time is 11:30")
hexchat.prnt((a[0].split("@"))[-1])
#hexchat.prnt(str(a)+str(b)+str(c))
return hexchat.EAT_NONE
def fizzbuzz(a,b,c):
for i in range(1,100):
if i%3:
if i%5:
hexchat.command("say "+str(i))
else:
hexchat.command("say fizzbuzz")
else:
if i%5:
hexchat.command("say fizz")
else:
hexchat.command("say fizzbuzz")
return hexchat.EAT_NONE
class loader:
def __init__(s):
s.fizz = False
s.chan = False
s.msg = False
s.nim = False
def on(s,a,b,c):
if a[1] == "fizz":
s.fizz = hexchat.hook_server("PRIVMSG",fizzbuzz)
hexchat.prnt ("fizz on")
elif a[1] == "chan":
s.chan = hexchat.hook_server("JOIN",chanreply)
hexchat.prnt ("chan on")
elif a[1] == "msg":
s.msg = hexchat.hook_server("PRIVMSG",reply)
hexchat.prnt("msg on")
elif a[1] == "nim":
tmp=nim()
s.nim = hexchat.hook_server("PRIVMSG",tmp.nimmove)
else:
hexchat.prnt("arguments must be valid")
return hexchat.EAT_HEXCHAT
def off(s,a,b,c):
if a[1] == "fizz":
hexchat.unhook(s.fizz)
s.fizz = 0
elif a[1] == "chan":
hexchat.unhook(s.chan)
s.chan = 0
elif a[1] == "msg":
hexchat.unhook(s.msg)
s.msg = 0
elif a[1] == "nim":
hexchat.unhook(s.nim)
s.nim = 0
else:
hexchat.prnt("args must be valid")
return hexchat.EAT_HEXCHAT
load = loader()
hexchat.hook_command("on",load.on)
hexchat.hook_command("off",load.off)
hexchat.prnt("init")