improved many things
added stuff like !restart, !fping etc for admins only
This commit is contained in:
parent
9151570c73
commit
20d40cb742
@ -3,22 +3,29 @@ import botconfig
|
|||||||
|
|
||||||
def generate(fdict, **kwargs):
|
def generate(fdict, **kwargs):
|
||||||
"""Generates a decorator generator. Always use this"""
|
"""Generates a decorator generator. Always use this"""
|
||||||
def cmd(*s, raw_nick=False, admin_only=False):
|
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False):
|
||||||
def dec(f):
|
def dec(f):
|
||||||
def innerf(*args):
|
def innerf(*args):
|
||||||
largs = list(args)
|
largs = list(args)
|
||||||
if not raw_nick and largs[1]:
|
if not raw_nick and largs[1]:
|
||||||
|
cloak = parse_nick(largs[1])[3]
|
||||||
largs[1] = parse_nick(largs[1])[0]
|
largs[1] = parse_nick(largs[1])[0]
|
||||||
if admin_only:
|
if owner_only:
|
||||||
if largs[1] and largs[1] in botconfig.ADMINS:
|
if cloak and cloak == botconfig.OWNER:
|
||||||
return f(*largs)
|
return f(*largs)
|
||||||
else:
|
elif cloak:
|
||||||
|
largs[0].notice(largs[1], "You are not the owner.")
|
||||||
|
return
|
||||||
|
if admin_only:
|
||||||
|
if cloak and cloak in botconfig.ADMINS:
|
||||||
|
return f(*largs)
|
||||||
|
elif cloak:
|
||||||
largs[0].notice(largs[1], "You are not an admin.")
|
largs[0].notice(largs[1], "You are not an admin.")
|
||||||
return
|
return
|
||||||
return f(*largs)
|
return f(*largs)
|
||||||
for x in s:
|
for x in s:
|
||||||
fdict[x] = innerf
|
fdict[x] = innerf
|
||||||
return f
|
return innerf
|
||||||
|
|
||||||
return dec
|
return dec
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ def add_commands(d):
|
|||||||
@add_commands(("join",
|
@add_commands(("join",
|
||||||
"mode",
|
"mode",
|
||||||
"nick",
|
"nick",
|
||||||
"part"))
|
"part",
|
||||||
|
"kick"))
|
||||||
class IRCClient(object):
|
class IRCClient(object):
|
||||||
""" IRC Client class. This handles one connection to a server.
|
""" IRC Client class. This handles one connection to a server.
|
||||||
This can be used either with or without IRCApp ( see connect() docs )
|
This can be used either with or without IRCApp ( see connect() docs )
|
||||||
@ -120,7 +121,16 @@ class IRCClient(object):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
logging.info('connecting to {0}:{1}'.format(self.host, self.port))
|
logging.info('connecting to {0}:{1}'.format(self.host, self.port))
|
||||||
self.socket.connect(("{0}".format(self.host), self.port))
|
retries = 0
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self.socket.connect(("{0}".format(self.host), self.port))
|
||||||
|
break
|
||||||
|
except socket.error as e:
|
||||||
|
retries += 1
|
||||||
|
logging.warning('Error: {0}'.format(e))
|
||||||
|
if retries > 3:
|
||||||
|
break
|
||||||
if not self.blocking:
|
if not self.blocking:
|
||||||
self.socket.setblocking(0)
|
self.socket.setblocking(0)
|
||||||
|
|
||||||
|
110
wolfgame.py
110
wolfgame.py
@ -9,6 +9,8 @@ import copy
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
COMMANDS = {}
|
COMMANDS = {}
|
||||||
PM_COMMANDS = {}
|
PM_COMMANDS = {}
|
||||||
@ -43,7 +45,7 @@ def connect_callback(cli):
|
|||||||
var.GRAVEYARD_LOCK = threading.Lock()
|
var.GRAVEYARD_LOCK = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
@cmd("!say")
|
@pmcmd("!say")
|
||||||
def say(cli, nick, rest): # To be removed later
|
def say(cli, nick, rest): # To be removed later
|
||||||
cli.msg(botconfig.CHANNEL, "{0} says: {1}".format(nick, rest))
|
cli.msg(botconfig.CHANNEL, "{0} says: {1}".format(nick, rest))
|
||||||
|
|
||||||
@ -111,22 +113,67 @@ def forced_exit(cli, nick, *rest): # Admin Only
|
|||||||
dict.clear(COMMANDS)
|
dict.clear(COMMANDS)
|
||||||
dict.clear(PM_COMMANDS)
|
dict.clear(PM_COMMANDS)
|
||||||
dict.clear(PM_COMMANDS)
|
dict.clear(PM_COMMANDS)
|
||||||
sleep(5)
|
|
||||||
cli.quit("Forced quit from admin")
|
cli.quit("Forced quit from admin")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cmd("!exec", admin_only=True)
|
@cmd("!exec", owner_only = True)
|
||||||
def py(cli, nick, chan, rest):
|
def py(cli, nick, chan, rest):
|
||||||
try:
|
try:
|
||||||
exec(rest)
|
exec(rest)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
cli.msg(chan, str(type(e))+":"+str(e))
|
cli.msg(chan, str(type(e))+":"+str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@cmd("!eval", owner_only = True)
|
||||||
|
def pyeval(cli, nick, chan, rest):
|
||||||
|
try:
|
||||||
|
a = str(eval(rest))
|
||||||
|
if len(a) < 500:
|
||||||
|
cli.msg(chan, a)
|
||||||
|
else:
|
||||||
|
cli.msg(chan, a[0:500])
|
||||||
|
except Exception as e:
|
||||||
|
cli.msg(chan, str(type(e))+":"+str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@cmd("!restart", admin_only=True)
|
||||||
|
def restart_program(cli, nick, chan, rest):
|
||||||
|
try:
|
||||||
|
forced_exit(cli, nick, chan, rest)
|
||||||
|
finally:
|
||||||
|
print("RESTARTING!")
|
||||||
|
python = sys.executable
|
||||||
|
os.execl(python, python, *sys.argv)
|
||||||
|
|
||||||
|
|
||||||
|
@cmd("!op", admin_only=True)
|
||||||
|
def give_op(cli, nick, chan, rest):
|
||||||
|
if not rest.strip():
|
||||||
|
rest = nick
|
||||||
|
cli.msg("ChanServ", " ".join(("op",chan,rest.strip())))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@cmd("!deop", admin_only=True)
|
||||||
|
def take_op(cli, nick, chan, rest):
|
||||||
|
if not rest.strip():
|
||||||
|
rest = nick
|
||||||
|
cli.msg("ChanServ", " ".join(("deop",chan,rest.strip())))
|
||||||
|
|
||||||
|
|
||||||
|
@cmd("!sudo revoke", owner_only=True)
|
||||||
|
def revoke(cli, nick, chan, rest):
|
||||||
|
r = rest.strip()
|
||||||
|
if r in botconfig.ADMINS:
|
||||||
|
ladmins = list(botconfig.ADMINS)
|
||||||
|
ladmins.remove(r)
|
||||||
|
botconfig.ADMINS = tuple(ladmins)
|
||||||
|
cli.msg(chan, "Revoked admin rights for \u0002{0}\u0002.".format(r))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cmd("!ping")
|
@cmd("!ping")
|
||||||
def pinger(cli, nick, chan, rest):
|
def pinger(cli, nick, chan, rest):
|
||||||
@ -172,7 +219,7 @@ def pinger(cli, nick, chan, rest):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cmd("!sudo ping", admin_only=True)
|
@cmd("!fping", admin_only=True)
|
||||||
def fpinger(cli, nick, chan, rest):
|
def fpinger(cli, nick, chan, rest):
|
||||||
var.LAST_PING = None
|
var.LAST_PING = None
|
||||||
pinger(cli, nick, chan, rest)
|
pinger(cli, nick, chan, rest)
|
||||||
@ -200,27 +247,41 @@ def join(cli, nick, chan, rest):
|
|||||||
cli.msg(chan, '\u0002{0}\u0002 has joined the game.'.format(nick))
|
cli.msg(chan, '\u0002{0}\u0002 has joined the game.'.format(nick))
|
||||||
|
|
||||||
|
|
||||||
@cmd("!fjoin")
|
@cmd("!fjoin", admin_only=True)
|
||||||
def fjoin(cli, nick, chan, rest):
|
def fjoin(cli, nick, chan, rest):
|
||||||
if nick in ("nyuszika7h", "jcao219"):
|
for a in rest.split(" "):
|
||||||
for a in rest.split(" "):
|
a = a.strip()
|
||||||
a = a.strip()
|
if a != botconfig.NICK:
|
||||||
if a != botconfig.NICK:
|
join(cli, a.strip(), chan, "")
|
||||||
join(cli, a.strip(), chan, "")
|
|
||||||
|
|
||||||
@cmd("!fleave")
|
@cmd("!fleave", admin_only=True)
|
||||||
def fleave(cli, nick, chan, rest):
|
def fleave(cli, nick, chan, rest):
|
||||||
if nick in ("nyuszika7h", "jcao219"):
|
for a in rest.split(" "):
|
||||||
for a in rest.split(" "):
|
a = a.strip()
|
||||||
a = a.strip()
|
if a.lower() != botconfig.NICK.lower():
|
||||||
if a.lower() != botconfig.NICK.lower():
|
del_player(cli, a.strip())
|
||||||
del_player(cli, a.strip())
|
cli.msg(chan, ("\u0002{0}\u0002 has used fleave"+
|
||||||
|
" on \u0002{1}\u0002.").format(nick, a.strip()))
|
||||||
|
|
||||||
@cmd("!fstart")
|
@cmd("!fstart", admin_only=True)
|
||||||
def fstart(cli, nick, chan, rest):
|
def fstart(cli, nick, chan, rest):
|
||||||
if nick not in ("nyuszika7h", "jcao219"): return
|
|
||||||
var.CAN_START_TIME = datetime.now()
|
var.CAN_START_TIME = datetime.now()
|
||||||
start(cli, nick, chan, rest)
|
start(cli, nick, chan, rest)
|
||||||
|
|
||||||
|
@cmd("!chankick", admin_only=True)
|
||||||
|
def chankick(cli, nick, chan, rest):
|
||||||
|
rest = rest.split(" ", 1)
|
||||||
|
if rest[0] != botconfig.NICK:
|
||||||
|
cli.kick(chan, *rest)
|
||||||
|
else:
|
||||||
|
cli.kick(chan, nick, "No.")
|
||||||
|
|
||||||
|
@hook("kick")
|
||||||
|
def on_kicked(cli, nick, chan, victim, reason):
|
||||||
|
if victim == botconfig.NICK:
|
||||||
|
cli.join(botconfig.CHANNEL)
|
||||||
|
cli.kick(chan, nick, "No.")
|
||||||
|
|
||||||
|
|
||||||
@cmd("!stats")
|
@cmd("!stats")
|
||||||
def stats(cli, nick, chan, rest):
|
def stats(cli, nick, chan, rest):
|
||||||
@ -725,6 +786,8 @@ def chk_nightdone(cli):
|
|||||||
(not var.ROLES["wolf"] + var.ROLES["werecrow"])) and
|
(not var.ROLES["wolf"] + var.ROLES["werecrow"])) and
|
||||||
var.PHASE == "night"): # no wolves
|
var.PHASE == "night"): # no wolves
|
||||||
if var.TIMERS[0]:
|
if var.TIMERS[0]:
|
||||||
|
if var.TIMERS[0].is_alive():
|
||||||
|
return
|
||||||
var.TIMERS[0].cancel() # cancel timer
|
var.TIMERS[0].cancel() # cancel timer
|
||||||
var.TIMERS[0] = None
|
var.TIMERS[0] = None
|
||||||
if var.PHASE == "night": # Double check
|
if var.PHASE == "night": # Double check
|
||||||
@ -1283,6 +1346,7 @@ def start(cli, nick, chan, rest):
|
|||||||
|
|
||||||
# DEATH TO IDLERS!
|
# DEATH TO IDLERS!
|
||||||
reapertimer = threading.Thread(None, reaper, args=(cli,))
|
reapertimer = threading.Thread(None, reaper, args=(cli,))
|
||||||
|
reapertimer.daemon = True
|
||||||
reapertimer.start()
|
reapertimer.start()
|
||||||
|
|
||||||
|
|
||||||
@ -1334,7 +1398,7 @@ def nay(cli, nick, chan, rest):
|
|||||||
cli.notice(nick, "You are already in the opposition.")
|
cli.notice(nick, "You are already in the opposition.")
|
||||||
return
|
return
|
||||||
var.SETTINGS_CHANGE_OPPOSITION.append(nick)
|
var.SETTINGS_CHANGE_OPPOSITION.append(nick)
|
||||||
needed = len(pl)//2 + 1
|
needed = max(len(pl)//2 + 1, 2)
|
||||||
if len(var.SETTINGS_CHANGE_OPPOSITION) >= needed:
|
if len(var.SETTINGS_CHANGE_OPPOSITION) >= needed:
|
||||||
cli.msg(chan, "The settings change request has been downvoted "+
|
cli.msg(chan, "The settings change request has been downvoted "+
|
||||||
"to oblivion. The default settings are restored.")
|
"to oblivion. The default settings are restored.")
|
||||||
|
Loading…
Reference in New Issue
Block a user