Compare commits

...

6 Commits

3 changed files with 92 additions and 6 deletions

2
bot.py
View File

@ -194,6 +194,6 @@ class IRCBot:
if teardown is not None: teardown()
if __name__=="__main__":
bot = IRCBot("bunbot","bunbot",channels=["#bungame"])
bot = IRCBot("teambun","teambun",channels=["#teambun"])
bot.load_modules()
bot.start()

View File

@ -1,6 +1,6 @@
from events import Event
from bot import IRCLine
ADMIN_HOSTMASKS = [x+"!khuxkm@fuckup.club" for x in "khuxkm".split()]
ADMIN_HOSTMASKS = [x+"!~lovetocode@3.1415926535897932384626433832795028841971693993751058209749445" for x in "lovetocode999".split()]
BOT = None
def admin(event):

View File

@ -21,6 +21,7 @@ if "bun_time" not in bungame_data: bungame_data["bun_time"]=time.time()
if "buns" not in bungame_data: bungame_data["buns"]=dict()
if "score_cache" not in bungame_data: bungame_data["score_cache"]=dict()
if "association" not in bungame_data: bungame_data["association"]=dict()
if "teams" not in bungame_data: bungame_data["teams"]=dict()
def check_bun_active(channel):
"""Checks if a bun is active in channel.
@ -92,18 +93,25 @@ def on_befriend(event):
if "account" not in event.tags:
respond(event,"You need a NickServ account to participate in the bun game! (/msg NickServ help register)")
return
account = event.tags["account"]
team = False
for i in bungame_data["teams"]:
if account in bungame_data["teams"][i]:
team = i
if not team:
respond(event,"You are not a part of any team!")
return
if not check_bun_active(event.target):
respond(event,"You missed the bun!")
return
account = event.tags["account"]
score, final_delta = get_bun_score(event.target)
deactivate_bun(event.target)
first_bun = False
# add the bun to their account and regenerate the score cache
try:
bungame_data["buns"][account].append(final_delta)
bungame_data["buns"][team].append(final_delta)
except KeyError:
bungame_data["buns"][account]=[final_delta]
bungame_data["buns"][team]=[final_delta]
bungame_data.save()
redo_score_cache()
# now tell them about it
@ -132,7 +140,14 @@ def on_stats(event):
respond(event,"You need a NickServ account to participate. (/msg NickServ help register)")
return
account = event.tags["account"]
buns = bungame_data["buns"].get(account)
team = False
for i in bungame_data["teams"]:
if account in bungame_data["teams"][i]:
team = i
if not team:
respond(event,"You are not a part of any team!")
return
buns = bungame_data["buns"].get(team)
if not buns:
respond(event,"You haven't befriended any buns!")
return
@ -165,6 +180,46 @@ def on_top10(event):
out=out[:-2]
respond(event,out)
def on_listteams(event):
out = f"Teams: "
for i in bungame_data["teams"]:
out += "{team} (, ".format(team=i)
for j in range(len(bungame_data["teams"][i])):
out = out[:len(out) - 2]
out += "{act}, ".format(act=bungame_data["teams"][i][j])
out = out[:-2]
out += "), "
out = out[:-2]
respond(event,out)
def on_jointeam(event):
if not event.target.startswith("#"): return
if "account" not in event.tags:
respond(event,"You need a NickServ account to participate. (/msg NickServ help register)")
return
account = event.tags["account"]
curTeam = False
for i in bungame_data["teams"]:
if account in bungame_data["teams"][i]:
curTeam = i
if curTeam:
respond(event,"You are already a part of {team} team!".format(team=curTeam))
return
try:
newTeam = event.parts[0]
except:
respond(event,"Syntax: join <team name>")
return
if not newTeam in bungame_data["teams"]:
respond(event,f"Team {newTeam} does not exist! Use -listteams to see the existing teams.")
try:
bungame_data["teams"][newTeam].append(account)
except KeyError:
bungame_data["teams"][newTeam]=[account]
bungame_data.save()
redo_score_cache()
respond(event,f"Team joined: {newTeam}")
def admin_redocache(event):
redo_score_cache()
respond(event,"Score cache redone!")
@ -182,6 +237,31 @@ def admin_merge(event):
redo_score_cache()
respond(event,"Should be merged now!")
def admin_newteam(event):
try:
team = event.parts[0]
except:
respond(event,"Syntax: admin newteam <team name>")
return
bungame_data["teams"][team] = []
bungame_data.save()
redo_score_cache()
respond(event,"Team created: "+team)
def admin_delteam(event):
try:
team = event.parts[0]
except:
respond(event,"Syntax: admin delteam <team name>")
return
if not team in bungame_data["teams"]:
respond(event,"Team "+team+" does not exist!")
return
del bungame_data["teams"][team]
bungame_data.save()
redo_score_cache()
respond(event,"Team deleted: "+team)
def register(bot):
global BOT
BOT=bot
@ -192,5 +272,11 @@ def register(bot):
bot.event_manager.on("command_peek",on_peek)
bot.event_manager.on("command_stats",on_stats)
bot.event_manager.on("command_top10",on_top10)
bot.event_manager.on("command_listteams",on_listteams)
bot.event_manager.on("command_jointeam",on_jointeam)
bot.event_manager.on("admin_redocache",admin_redocache)
bot.event_manager.on("admin_merge",admin_merge)
bot.event_manager.on("admin_newteam",admin_newteam)
bot.event_manager.on("admin_delteam",admin_delteam)
# vim:shiftwidth=0:noexpandtab