Compare commits
7 Commits
818d4afdb0
...
6297b790df
Author | SHA1 | Date |
---|---|---|
randomuser | 6297b790df | |
randomuser | ce7ea7ea60 | |
randomuser | 7ab890cf51 | |
randomuser | 7aac5d09a0 | |
randomuser | 48096c3c6b | |
randomuser | 75054c469a | |
randomuser | 1e9794c8ca |
67
bot.py
67
bot.py
|
@ -15,13 +15,13 @@ from secrets import PASSWORD
|
|||
|
||||
channels = [
|
||||
"#bots",
|
||||
# "#club",
|
||||
"#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/Fs4.txt for more information."
|
||||
|
||||
def userchooser(user):
|
||||
return random.choice([i for i in os.listdir(r"/home") if i[0] == user[0]])
|
||||
return random.choice([i for i in os.listdir(r"/home") if i.lower()[0] == user.lower()[0]])
|
||||
|
||||
# borrowed from kiedtl/ircbot
|
||||
async def _aexec(self, code):
|
||||
|
@ -37,7 +37,7 @@ class Server(BaseServer):
|
|||
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
|
||||
if abs(self.drunkentime - int(time.time())) > 60 * 4: return True
|
||||
return False
|
||||
async def line_read(self, line: Line):
|
||||
print(f"{self.name} < {line.format()}")
|
||||
|
@ -55,14 +55,23 @@ class Server(BaseServer):
|
|||
if line.params[-1][0] == '%':
|
||||
commands = line.params[-1][1:].split(' ')
|
||||
if commands[0] == "score":
|
||||
if len(commands) == 2:
|
||||
if self.isDrunk(): b = Botany(commands[1])
|
||||
else:
|
||||
if len(commands) == 1: commands.append(user)
|
||||
if self.isDrunk(): b = Botany(commands[1])
|
||||
else:
|
||||
b = Botany(userchooser(commands[1]))
|
||||
while b.getInfo() == []:
|
||||
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)
|
||||
i = b.getInfo()
|
||||
await self.msg(channel, "{}'s score: {}".format(b.user, str(int(b.score()))), user)
|
||||
elif commands[0] == "pct":
|
||||
if len(commands) == 1: commands.append(user)
|
||||
b = Botany(commands[1])
|
||||
i = b.getInfo()
|
||||
if len(i) > 1:
|
||||
pct = (1 - ((time.time() - i['last_watered'])/86400)) * 100
|
||||
await self.msg(channel, "plant percentage for {}: {}%".format(b.user, int(pct)), user)
|
||||
else:
|
||||
await self.msg(channel, "couldn't find plant for {}".format(commands[1]), user)
|
||||
elif commands[0] == "vodka":
|
||||
if self.isDrunk():
|
||||
self.drunkentime = int(time.time())
|
||||
|
@ -70,27 +79,25 @@ class Server(BaseServer):
|
|||
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)
|
||||
if len(commands) == 1: commands.append(user)
|
||||
if self.isDrunk():
|
||||
b = Botany(commands[1])
|
||||
else:
|
||||
await self.msg(channel, "specify user", user)
|
||||
b = Botany(userchooser(commands[1]))
|
||||
await self.msg(channel, b.plantDescription(), user)
|
||||
elif commands[0] == "water":
|
||||
if len(commands) == 2:
|
||||
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:
|
||||
b = Botany(userchooser(commands[1]))
|
||||
while not b.water("{} (via IRC".format(user)):
|
||||
b = Botany(userchooser(commands[1]))
|
||||
if len(commands) == 1: commands.append(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:
|
||||
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":
|
||||
|
@ -98,6 +105,10 @@ 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)
|
||||
else:
|
||||
await self.msg(channel, "you're not an admin", user)
|
||||
else:
|
||||
await self.msg(channel, "specify the channel", user)
|
||||
elif commands[0] == "addowner":
|
||||
if len(commands) == 2:
|
||||
if user == self.admin:
|
||||
|
|
13
botany.py
13
botany.py
|
@ -7,8 +7,9 @@ class Botany:
|
|||
plant = "/home/{}/.botany/{}_plant_data.json"
|
||||
def __init__(self, user):
|
||||
self.user = user
|
||||
self.euser = user.lower()
|
||||
def getVisitors(self):
|
||||
formatted = self.visitors.format(self.user)
|
||||
formatted = self.visitors.format(self.euser)
|
||||
try:
|
||||
if os.stat(formatted).st_size > 0:
|
||||
with open(formatted) as fd:
|
||||
|
@ -20,7 +21,7 @@ class Botany:
|
|||
return False
|
||||
def insertVisitor(self, data, waterer):
|
||||
if data == False: return False
|
||||
formatted = self.visitors.format(self.user)
|
||||
formatted = self.visitors.format(self.euser)
|
||||
data.append({"timestamp": int(time.time()), "user": waterer})
|
||||
try:
|
||||
with open(formatted, "w") as fd:
|
||||
|
@ -33,7 +34,7 @@ class Botany:
|
|||
print("FileNotFoundError in insertVisitor()")
|
||||
return False
|
||||
def getInfo(self):
|
||||
formatted = self.plant.format(self.user, self.user)
|
||||
formatted = self.plant.format(self.euser, self.euser)
|
||||
try:
|
||||
with open(formatted) as fd:
|
||||
return json.load(fd)
|
||||
|
@ -42,16 +43,16 @@ class Botany:
|
|||
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
|
||||
if len(i) > 1: return i['score'] + min(i['last_watered'] - int(time.time()), 24 * 3600) * 0.2 * (i['generation'] - 1) + 1
|
||||
return 0
|
||||
|
||||
class IRCBotany(Botany):
|
||||
def plantDescription(self):
|
||||
string = ""
|
||||
data = self.getInfo()
|
||||
if(data == []): return "{}'s invisible plant".format(self.user)
|
||||
if(data == []): return "{}'s invisible plant".format(self.euser)
|
||||
|
||||
string += self.user
|
||||
print(self.user)
|
||||
string += "'s "
|
||||
if(data['is_dead']): string += "dead "
|
||||
string += data['description']
|
||||
|
|
Loading…
Reference in New Issue