Updated plugins to work with asyncio.
This commit is contained in:
parent
b1f6ca23c5
commit
bc8424c1c8
2 changed files with 25 additions and 30 deletions
33
commands.py
33
commands.py
|
@ -5,55 +5,50 @@ from src.plugin_base import PluginBase
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginBase):
|
class Plugin(PluginBase):
|
||||||
def handle_message(self, source_nick, channel, message):
|
async def handle_message(self, source_nick, channel, message):
|
||||||
message_parts = message.split()
|
message_parts = message.split()
|
||||||
self.channel_manager = ChannelManager()
|
self.channel_manager = ChannelManager()
|
||||||
if message_parts[0] == '!hello':
|
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Hello, {source_nick}!')
|
|
||||||
|
|
||||||
|
if message_parts[0] == '!hello':
|
||||||
|
await self.bot.ircsend(f'PRIVMSG {channel} :Hello, {source_nick}!')
|
||||||
elif message_parts[0] == '!join':
|
elif message_parts[0] == '!join':
|
||||||
if len(message_parts) == 0:
|
if len(message_parts) == 0:
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Please specify a channel to join')
|
await self.bot.ircsend(f'PRIVMSG {channel} :Please specify a channel to join')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.channel_manager.save_channel(message_parts[1])
|
self.channel_manager.save_channel(message_parts[1])
|
||||||
self.bot.ircsend(f'JOIN {message_parts[1]}')
|
await self.bot.ircsend(f'JOIN {message_parts[1]}')
|
||||||
|
|
||||||
elif message_parts[0] == '!part':
|
elif message_parts[0] == '!part':
|
||||||
if len(message_parts) == 1:
|
if len(message_parts) == 1:
|
||||||
self.bot.ircsend(f'PART {channel}')
|
await self.bot.ircsend(f'PART {channel}')
|
||||||
self.channel_manager.remove_channel(channel)
|
self.channel_manager.remove_channel(channel)
|
||||||
else:
|
else:
|
||||||
self.bot.ircsend(f'PART {message_parts[1]}')
|
await self.bot.ircsend(f'PART {message_parts[1]}')
|
||||||
self.channel_manager.remove_channel(message_parts[1])
|
self.channel_manager.remove_channel(message_parts[1])
|
||||||
|
|
||||||
elif message_parts[0] == '!quit':
|
elif message_parts[0] == '!quit':
|
||||||
if len(message_parts) == 0:
|
if len(message_parts) == 0:
|
||||||
quit_message = 'EliteBot!'
|
quit_message = 'EliteBot!'
|
||||||
else:
|
else:
|
||||||
quit_message = message[len(message_parts[0]) + 1:]
|
quit_message = message[len(message_parts[0]) + 1:]
|
||||||
self.bot.ircsend(f'QUIT :{quit_message}')
|
await self.bot.ircsend(f'QUIT :{quit_message}')
|
||||||
self.bot.ircsock.close()
|
await self.bot.ircsock.close()
|
||||||
self.bot.connected = False
|
self.bot.connected = False
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif message_parts[0] == '!raw':
|
elif message_parts[0] == '!raw':
|
||||||
if len(message_parts) > 1:
|
if len(message_parts) > 1:
|
||||||
if message_parts[1].upper() == 'PRIVMSG' and len(message_parts) > 3:
|
if message_parts[1].upper() == 'PRIVMSG' and len(message_parts) > 3:
|
||||||
raw_command = ' '.join(message_parts[1:3]) + " :" + ' '.join(message_parts[3:])
|
raw_command = ' '.join(message_parts[1:3]) + " :" + ' '.join(message_parts[3:])
|
||||||
else:
|
else:
|
||||||
raw_command = ' '.join(message_parts[1:])
|
raw_command = ' '.join(message_parts[1:])
|
||||||
self.bot.ircsend(raw_command)
|
await self.bot.ircsend(raw_command)
|
||||||
|
|
||||||
elif message_parts[0] == '!me':
|
elif message_parts[0] == '!me':
|
||||||
if len(message_parts) > 1:
|
if len(message_parts) > 1:
|
||||||
action_message = ' '.join(message_parts[1:])
|
action_message = ' '.join(message_parts[1:])
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :\x01ACTION {action_message}\x01')
|
await self.bot.ircsend(f'PRIVMSG {channel} :\x01ACTION {action_message}\x01')
|
||||||
else:
|
else:
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Please specify an action')
|
await self.bot.ircsend(f'PRIVMSG {channel} :Please specify an action')
|
||||||
|
|
||||||
elif message_parts[0] == '!ping':
|
elif message_parts[0] == '!ping':
|
||||||
if len(message_parts) > 1:
|
if len(message_parts) > 1:
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Pinging {message_parts[1]}')
|
await self.bot.ircsend(f'PRIVMSG {channel} :Pinging {message_parts[1]}')
|
||||||
else:
|
else:
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Please specify a nick to ping')
|
await self.bot.ircsend(f'PRIVMSG {channel} :Please specify a nick to ping')
|
||||||
|
|
22
cookie.py
22
cookie.py
|
@ -22,7 +22,7 @@ df = '%Y/%m/%d %H:%M:%S'
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginBase):
|
class Plugin(PluginBase):
|
||||||
def handle_message(self, source_nick, channel, message):
|
async def handle_message(self, source_nick, channel, message):
|
||||||
parts = message.split()
|
parts = message.split()
|
||||||
c_db.create_table('Cookie')
|
c_db.create_table('Cookie')
|
||||||
self.channel_manager = ChannelManager()
|
self.channel_manager = ChannelManager()
|
||||||
|
@ -31,9 +31,9 @@ class Plugin(PluginBase):
|
||||||
if len(parts) == 1:
|
if len(parts) == 1:
|
||||||
self.insert_user(source_nick)
|
self.insert_user(source_nick)
|
||||||
|
|
||||||
cookies = c_db.get(source_nick, 2)
|
cookies = c_db.get_user(source_nick, 2)
|
||||||
rnd = random.randint(1, 10)
|
rnd = random.randint(1, 10)
|
||||||
last = datetime.strptime(c_db.get(source_nick, 3), df)
|
last = datetime.strptime(c_db.get_user(source_nick, 3), df)
|
||||||
current = datetime.strptime(datetime.now().strftime(df), df)
|
current = datetime.strptime(datetime.now().strftime(df), df)
|
||||||
diff = round((current - last).total_seconds() / 60.0)
|
diff = round((current - last).total_seconds() / 60.0)
|
||||||
|
|
||||||
|
@ -45,27 +45,27 @@ class Plugin(PluginBase):
|
||||||
else f'{(cookies + rnd)} cookie' if (cookies + rnd) == 1 \
|
else f'{(cookies + rnd)} cookie' if (cookies + rnd) == 1 \
|
||||||
else f'{(cookies + rnd)} cookies'
|
else f'{(cookies + rnd)} cookies'
|
||||||
|
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :\x01ACTION gives {c1} to {source_nick}.\x01')
|
await self.bot.ircsend(f'PRIVMSG {channel} :\x01ACTION gives {c1} to {source_nick}.\x01')
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :You now have a total of {c2}.')
|
await self.bot.ircsend(f'PRIVMSG {channel} :You now have a total of {c2}.')
|
||||||
|
|
||||||
c_db.set(source_nick, {
|
c_db.set_user(source_nick, {
|
||||||
'cookies': (cookies + rnd),
|
'cookies': (cookies + rnd),
|
||||||
'last': current.strftime(df)
|
'last': current.strftime(df)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
rem = self.remaining_time(last.strftime(df), 30 * 60000)
|
rem = self.remaining_time(last.strftime(df), 30 * 60000)
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Remaining time: {rem}')
|
await self.bot.ircsend(f'PRIVMSG {channel} :Remaining time: {rem}')
|
||||||
elif len(parts) == 2:
|
elif len(parts) == 2:
|
||||||
cookies = c_db.get(parts[1], 2)
|
cookies = c_db.get_user(parts[1], 2)
|
||||||
|
|
||||||
if cookies == -1:
|
if cookies == -1:
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :I\'ve looked everywhere for {parts[1]}, but I couldn\'t '
|
await self.bot.ircsend(f'PRIVMSG {channel} :I\'ve looked everywhere for {parts[1]}, but I couldn\'t '
|
||||||
f'find them.')
|
f'find them.')
|
||||||
else:
|
else:
|
||||||
c = 'no cookies' if cookies == 0 \
|
c = 'no cookies' if cookies == 0 \
|
||||||
else f'{cookies} cookie' if cookies == 1 \
|
else f'{cookies} cookie' if cookies == 1 \
|
||||||
else f'{cookies} cookies'
|
else f'{cookies} cookies'
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :{parts[1]} currently has {c}.')
|
await self.bot.ircsend(f'PRIVMSG {channel} :{parts[1]} currently has {c}.')
|
||||||
|
|
||||||
def insert_user(self, user: str):
|
def insert_user(self, user: str):
|
||||||
with c_db.engine.connect() as conn:
|
with c_db.engine.connect() as conn:
|
||||||
|
|
Loading…
Add table
Reference in a new issue