-
Notifications
You must be signed in to change notification settings - Fork 0
/
notice_verlihub.py
112 lines (92 loc) · 3.11 KB
/
notice_verlihub.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
##author hari_om
##email: [email protected]
#######################################
####################uses###########################
#commands: !notice add <notice to be added>
#commands: !notice list
#commands: !notice del <id of notice>
#for ex to add notice run: !notice add Sample message of the day
#this will add a notice of "Sample message of the day"
#for ex to list all notice !notice list
#this will show all notice with their ids and valid time
#for deleting a particular notice
#first get id of the notcie then run: !notice del 22
#this will delte notice whose id is 22
####################requirements###################
# make a table named notice with three column id , msg, and utcvalid
#create table notice ( id integer(20) primary key auto_increment, msg varchar(1000), utcvalid integer(20))
#change permission of motd file to rw and create a file motd_intro with read permission which will contain the starting texts which will be always shown
#chmod a+rwx motd
#chmod a+rwx motd_intro
import vh
import MySQLdb as mdb
import sys
import string
motd_intro_path='/etc/verlihub/motd_intro'
motd_path='/etc/verlihub/motd'
def OnOperatorCommand (nick, data):
#vh.pm(data,nick)
#print data
i= data.find(' ')
#print type(data)
#print data[1:i]
if data[1:i] == "notice":
stri=data[i+1:]
cmd=stri.split(' ')[0]
if cmd == "add":
i=stri.find(' ')
val=stri[i+1:]
con = mdb.connect('localhost', 'root', 'happyinbit', 'verlihub')
with con:
cur=con.cursor()
print 'inserting val'
cur.execute("insert into notice values(0,\'"+val+"\',123456)")
content=''
with open(motd_intro_path, 'r') as content_file:
content = content_file.read()
content_file=open(motd_path,'w')
content_file.write(content+'\n')
content_file.close()
cur.execute("select msg from notice")
rows=cur.fetchall()
motd_file=open(motd_path,'a')
for row in rows:
#print "writing"
motd_file.write("##########\n")
motd_file.write(row[0]+'\n')
motd_file.close()
return 1
if cmd== 'list':
con = mdb.connect('localhost', 'root', 'happyinbit', 'verlihub')
with con:
cur=con.cursor()
cur.execute("select id, utcvalid, msg from notice")
rows=cur.fetchall()
sendtxt='\nid\tutc valid\tmsg\n#############################################################\n\n'
for row in rows:
sendtxt=sendtxt+str(row[0])+'\t'+str(row[1])+'\t'+str(row[2])+'\n'
print sendtxt
vh.pm(sendtxt, nick)
return 1
if cmd =='del':
i=stri.find(' ')
val=stri[i+1:]
con = mdb.connect('localhost', 'root', 'happyinbit', 'verlihub')
with con:
cur=con.cursor()
cur.execute("delete from notice where id ="+val)
content=''
with open(motd_intro_path, 'r') as content_file:
content = content_file.read()
content_file=open(motd_path,'w')
content_file.write(content+'\n')
content_file.close()
cur.execute("select msg from notice")
rows=cur.fetchall()
motd_file=open(motd_path,'a')
for row in rows:
#print "writing"
motd_file.write("##########\n")
motd_file.write(row[0]+'\n')
motd_file.close()
return 1