Initial commit
This commit is contained in:
commit
9f9725a472
1 file changed
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#import sys, irc, subprocess, ssl
|
||||||
|
#from irc import client, connection
|
||||||
|
import irc.bot, subprocess
|
||||||
|
import irc.strings
|
||||||
|
#from irc import connection, client
|
||||||
|
|
||||||
|
class TestBot(irc.bot.SingleServerIRCBot):
|
||||||
|
def __init__(self, channel, nickname, server, port=6667):
|
||||||
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
|
||||||
|
self.channel = channel
|
||||||
|
|
||||||
|
def on_welcome(self, c, e):
|
||||||
|
c.mode('nickname', '+B')
|
||||||
|
c.join(self.channel)
|
||||||
|
|
||||||
|
def on_privmsg(self, c, e):
|
||||||
|
self.do_command(e, e.arguments[0])
|
||||||
|
|
||||||
|
def on_pubmsg(self, c, e):
|
||||||
|
a = e.arguments[0].split(":", 1)
|
||||||
|
if len(a) > 1 and irc.strings.lower(a[0]) == irc.strings.lower(
|
||||||
|
self.connection.get_nickname()
|
||||||
|
):
|
||||||
|
self.do_command(e, a[1].strip())
|
||||||
|
return
|
||||||
|
|
||||||
|
def do_command(self, e, cmd):
|
||||||
|
nick = e.source.nick
|
||||||
|
c = self.connection
|
||||||
|
|
||||||
|
if cmd == "stats":
|
||||||
|
for chname, chobj in self.channels.items():
|
||||||
|
c.notice(nick, "--- Channel statistics ---")
|
||||||
|
c.notice(nick, "Channel: " + chname)
|
||||||
|
users = sorted(chobj.users())
|
||||||
|
c.notice(nick, "Users: " + ", ".join(users))
|
||||||
|
opers = sorted(chobj.opers())
|
||||||
|
c.notice(nick, "Opers: " + ", ".join(opers))
|
||||||
|
voiced = sorted(chobj.voiced())
|
||||||
|
c.notice(nick, "Voiced: " + ", ".join(voiced))
|
||||||
|
if cmd == "load":
|
||||||
|
result = subprocess.run(["uptime" ], stderr=subprocess.PIPE, stdout=subprocess.PIPE) #result.stdout.decode()
|
||||||
|
output = result.stdout.decode().strip()
|
||||||
|
res = output[output.find('load average'):]
|
||||||
|
c.notice(nick, res)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
channel = '#notifications'
|
||||||
|
nickname = 'GandCStat'
|
||||||
|
server = '10.200.201.4'
|
||||||
|
bot = TestBot(channel, nickname, server)
|
||||||
|
bot.start()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in new issue
Block a user