Compare commits

...

7 Commits

Author SHA1 Message Date
randomuser 818d4afdb0 the great documentation update RETURNS 2021-06-23 04:37:40 +00:00
randomuser 09d8f1de4b add misc commands 2021-06-23 04:33:12 +00:00
randomuser 5d381caf59 update .gitignore 2021-06-23 04:04:55 +00:00
randomuser 0f8e5d6c35 impliment an admin system 2021-06-23 04:04:09 +00:00
randomuser f26efff91f add scoring function 2021-06-23 03:57:08 +00:00
randomuser 5ba758e79d the great botany documentation update 2021-06-22 22:41:30 +00:00
randomuser 025f382554 oh crap it can get drunk 2021-06-22 22:40:48 +00:00
5 changed files with 147 additions and 11 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
secrets.py
__pycache__

10
admin.py Normal file
View File

@ -0,0 +1,10 @@
class Admin:
def __init__(self, nick):
self.nicks = []
self.nicks.append(nick)
def __eq__(self, val):
return val in self.nicks
def append(self, nick):
self.nicks.append(nick)
def remove(self, nick):
self.nicks.remove(nick)

100
bot.py
View File

@ -1,4 +1,7 @@
import asyncio
import os
import random
import time
from irctokens import build, Line
from ircrobots import Bot as BaseBot
@ -6,20 +9,36 @@ from ircrobots import Server as BaseServer
from ircrobots import ConnectionParams
from botany import IRCBotany as Botany
from admin import Admin
from secrets import PASSWORD
channels = [
"#bots",
# "#club",
"###",
]
helpmessage = "hey, i'm botanybot. i water plants on ~club. my prefix is % and i was made by randomuser. check out https://ttm.sh/Fki.txt for more information."
helpmessage = "hey, i'm botanybot. i water plants on ~club. my prefix is % and i was made by randomuser. check out https://ttm.sh/Fs4.txt for more information."
def userchooser(user):
return random.choice([i for i in os.listdir(r"/home") if i[0] == user[0]])
# borrowed from kiedtl/ircbot
async def _aexec(self, code):
# Make an async function with the code and `exec` it
exec(f"async def __ex(self): " + "".join(f"\n {l}" for l in code.split("\n")))
# Get `__ex` from local variables, call it and return the result
return await locals()["__ex"](self)
class Server(BaseServer):
admin = 'rndusr'
admin = Admin('rndusr')
async def msg(self, chan, string, user=None):
if user == None: await self.send(build("PRIVMSG", [chan, string]))
else: await self.send(build("PRIVMSG", [chan, user + ": " + string]))
def isDrunk(self):
if abs(self.drunkentime - int(time.time())) > 30: return True
return False
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
@ -27,6 +46,7 @@ class Server(BaseServer):
await self.msg("nickserv", "identify " + PASSWORD)
for i in channels:
await self.send(build("JOIN", [i]))
self.drunkentime = 0
if line.command == "PRIVMSG":
user = line.hostmask.nickname
channel = line.params[0]
@ -34,19 +54,43 @@ class Server(BaseServer):
await self.msg(channel, helpmessage, user)
if line.params[-1][0] == '%':
commands = line.params[-1][1:].split(' ')
if commands[0] == "desc":
if commands[0] == "score":
if len(commands) == 2:
b = Botany(commands[1])
if self.isDrunk(): b = Botany(commands[1])
else:
b = Botany(userchooser(commands[1]))
while b.getInfo() == []:
b = Botany(userchooser(commands[1]))
i = b.getInfo()
await self.msg(channel, "{}'s score: {}".format(b.user, str(int(b.score()))), user)
elif commands[0] == "vodka":
if self.isDrunk():
self.drunkentime = int(time.time())
await self.msg(channel, "glug glug glug", user)
else:
await self.msg(channel, "vodka? what's vodka? *burp*", user)
elif commands[0] == "desc":
if len(commands) == 2:
if self.isDrunk():
b = Botany(commands[1])
else:
b = Botany(userchooser(commands[1]))
await self.msg(channel, b.plantDescription(), user)
else:
await self.msg(channel, "specify user", user)
elif commands[0] == "water":
if len(commands) == 2:
b = Botany(commands[1])
if(b.water("{} (via IRC)".format(user))):
await self.msg(channel, b.watered(), user)
if self.isDrunk():
b = Botany(commands[1])
if b.water("{} (via IRC)".format(user)):
await self.msg(channel, b.watered(), user)
else:
await self.msg(channel, b.cantWater(), user)
else:
await self.msg(channel, b.cantWater(), user)
b = Botany(userchooser(commands[1]))
while not b.water("{} (via IRC".format(user)):
b = Botany(userchooser(commands[1]))
await self.msg(channel, b.watered(), user)
elif commands[0] == "help":
await self.msg(channel, helpmessage, user)
elif commands[0] == "join":
@ -54,11 +98,11 @@ class Server(BaseServer):
if user == self.admin:
await self.send(build("JOIN", [commands[1]]))
await self.msg(channel, "joined the channel {}".format(commands[1]), user)
elif commands[0] == "chowner":
elif commands[0] == "addowner":
if len(commands) == 2:
if user == self.admin:
self.admin = commands[1]
await self.msg(channel, "admin changed to {}".format(commands[1]), user)
self.admin.append(commands[1])
await self.msg(channel, "admin added: {}".format(commands[1]), user)
return
else:
await self.msg(channel, "error: you must be an admin!", user)
@ -66,6 +110,40 @@ class Server(BaseServer):
else:
await self.msg(channel, "two arguments required", user)
return
elif commands[0] == "delowner":
if len(commands) == 2:
if user == self.admin:
try: self.admin.remove(commands[1])
except:
await self.msg(channel, "problem with removing admin", user)
return
await self.msg(channel, "admin deleted: {}".format(commands[1]), user)
return
else:
await self.msg(channel, "error: you must be an admin!", user)
return
else:
await self.msg(channel, "two arguments required", user)
return
elif commands[0] == "amowner":
if user == self.admin:
await self.msg(channel, "you're an admin", user)
else:
await self.msg(channel, "you're not an admin", user)
elif commands[0] == "ping": await self.msg(channel, "pong", user)
elif commands[0] == "eval":
if user == self.admin:
text = ' '.join(line.params[-1][1:].split(' ')[1:])
try:
result = await _aexec(self, text)
except Exception as e:
await self.msg(channel, "segfault: {}".format(repr(e)), user)
return
await self.msg(channel, "{}".format(result), user)
else:
await self.msg(channel, "must have admin to execute", user)
async def line_send(self, line: Line):
print(f"{self.name} > {line.format()}")

View File

@ -40,6 +40,9 @@ class Botany:
except:
print("error in getInfo()")
return []
def score(self):
i = self.getInfo()
return i['score'] + min(i['last_watered'] - int(time.time()), 24 * 3600) * 0.2 * (i['generation'] - 1) + 1
class IRCBotany(Botany):
def plantDescription(self):

44
help.txt Normal file
View File

@ -0,0 +1,44 @@
tilde.club botany bot
=====================
commands
--------
!rollcall - supported only in #bots
see the help text for the bot
%desc <account>
see a person's plant description
- if there is no plant associated to the account, they will
have an 'invisible plant'
%desc nouser
nouser's invisible plant
%water <account>
water a person's plant
- if there is no plant associated to the account, this call
will error
%water nouser
I can't water nouser's invisible plant!
%join <channel>
make the bot join a channel
- requires admin privs
%join #chaos
joined the channel
%{add,del}owner <nick>
add or remove owner status from a nick (admins)
%amowner
determine if you are an owner
%ping
pong!
%eval <code>
evaluate the result of python code (admins)
see tildegit.org/randomuser/botanybot for the source