-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsummon.py
67 lines (60 loc) · 1.45 KB
/
summon.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
from util import hook
import os
def announce(text, conn, chan, action=None, nick=None):
conn.cmd("PRIVMSG " + chan + " " + str(text));
@hook.command('summon', permissions=["botcontrol"], autohelp=False)
def summon(inp, chan=None, conn=None):
if chan == "#eisenstein":
if inp == "!all":
open("summonlist.txt", 'a').close()
lockfile(chan)
conn.cmd("WHO", [chan])
else:
return "Calling " + inp + "."
@hook.event('352')
def who_summon(inp, conn=None, chan="#eisenstein"):
channel = str(inp[1])
if channel == "#eisenstein":
user = str(inp[5]);
store(user + ";")
@hook.event('315')
def end_summon(inp, conn=None, chan="#eisenstein"):
if os.path.exists("summon.lock"):
usrlist = retreive()
del usrlist[-1]
prettylist = ', '.join(usrlist)
announce(prettylist, conn, "#eisenstein");
os.remove("summonlist.txt")
os.remove("summon.lock")
def store(data):
try:
# MORE FUNCTIONS!!!
logfile = open("summonlist.txt", "a")
try:
logfile.write(data)
finally:
logfile.close()
except IOError:
pass
def retreive():
try:
f = open("summonlist.txt", "r")
try:
# Read the entire contents of a file at once.
args = f.read()
finally:
f.close()
except IOError:
string = "Could not read file."
arguments = args.split(";")
return arguments;
def lockfile(data):
try:
#Lockfile for tracking
summonlock = open("summon.lock", "a")
try:
summonlock.write(data)
finally:
summonlock.close()
except IOError:
pass