This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecalbot.py
executable file
·121 lines (103 loc) · 4.26 KB
/
recalbot.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import irclib
import ircbot
import settings
import os
import codecs
from zpaste import ZPaste
import time, threading
class Recalbot(ircbot.SingleServerIRCBot):
def __init__(self):
ircbot.SingleServerIRCBot.__init__(self, [(settings.SRV, settings.PORT, settings.PWD)], settings.NAME,
settings.DESC)
self.availableCmd = ["!mega", "!wiki", "!help","!histo","!op"]
self.megaLink = ""
self.wikiLink = ""
def on_welcome(self, serv, ev):
serv.join(settings.CHAN)
def on_kick(self, serv, ev):
serv.join(settings.CHAN)
#serv.action(settings.CHAN, "se sent bien ici")
def on_pubmsg(self, serv, ev):
self.auteur = irclib.nm_to_n(ev.source())
self.canal = ev.target()
self.message = ev.arguments()[0].decode('utf-8', errors='replace')
self.serv = serv
self.find_cmd_on_string(self.message)
info = '<'+time.strftime('%H:%M',time.localtime()) +"> "+self.auteur + ' : ' + self.message + '\n'
self.write_file(settings.HISTOF,"histo.txt", info)
def on_privmsg(self, serv, ev):
self.auteur = irclib.nm_to_n(ev.source())
self.canal = ev.target()
self.message = ev.arguments()[0].decode('utf-8', errors='replace')
self.serv = serv
#self.serv.mode("#test-recalbot", "+o MikaXII")
self.find_cmd_on_string(self.message)
self.find_godmode_on_string(self.message)
def find_cmd_on_string(self, string_with_cmd):
for cmd in self.availableCmd:
if cmd in string_with_cmd:
self.execute_cmd(cmd)
return True
return False
def on_join(self,serv,ev):
self.auteur = irclib.nm_to_n(ev.source())
self.canal = ev.target()
self.serv = serv
for user in settings.OP:
if user == self.auteur:
self.serv.mode("#recalbox", "+o "+self.auteur)
def find_godmode_on_string(self, string_with_cmd):
cmd = string_with_cmd.split(' ')
if(len(cmd) > 1):
if settings.GOD in cmd:
self.serv.kick(settings.CHAN,cmd[1],self.auteur + " activate god mode")
return True
return False
def execute_cmd(self, cmd):
if cmd == "!mega":
self.read_file("./links/mega.txt")
elif cmd=="!histo":
self.serv.privmsg(self.auteur, settings.HISTO)
elif cmd=="!wiki":
self.read_file("./links/wiki.txt")
elif cmd == "!help":
self.serv.privmsg(self.auteur, "If you want mega link say !mega, wiki pages say !wiki, channel history say !histo")
elif cmd == "!op":
for user in settings.OP:
if user in self.auteur:
self.serv.mode("#recalbox", "+o "+self.auteur)
def read_all_file(self, folder):
data = {}
for dir_entry in os.listdir(folder):
dir_entry_path = os.path.join(folder, dir_entry)
if os.path.isfile(dir_entry_path):
with codecs.open(dir_entry_path, 'r', encoding='utf8') as my_file:
data[dir_entry] = my_file.read()
self.paste_info(data);
def read_file(self,fileToRead):
data = ""
with codecs.open(fileToRead, 'r', encoding='utf8') as my_file:
data = my_file.read()
self.serv.privmsg(self.auteur,data)
def paste_info(self, info):
self.serv.privmsg(self.auteur, "Please wait I'm working for you :*")
a = ZPaste(info)
self.serv.privmsg(self.auteur, a.link)
del a
def write_file(self, folder, file, info):
with codecs.open(folder+'/'+file, 'r','utf-8',errors="replace") as fin:
data = fin.read().splitlines(True)
if len(data) >= 5000:
with codecs.open(folder+'/'+file, 'w', 'utf-8',errors="replace") as fout:
fout.writelines(data[1:])
fout.writelines(info)
else:
with codecs.open(folder+'/'+file, 'w', 'utf-8',errors="replace") as fout:
fout.writelines(data)
fout.writelines(info)
def periodicPast(self):
a = ZPaste
if __name__ == "__main__":
Recalbot().start()