globalforest/cncbot.py

58 lines
1.9 KiB
Python
Raw Normal View History

2020-10-17 12:22:22 -04:00
import pydle
import random
import string
2020-10-18 13:53:02 -04:00
CNC_HOST='forest.deflax.net'
2020-10-17 12:22:22 -04:00
ADMIN_NICKNAMES = [ 'afx' ]
def get_random_string(length):
letters = string.ascii_lowercase
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str
class ForestBot(pydle.Client):
async def on_connect(self):
await super().on_connect()
await self.join('#forest')
async def is_admin(self, nickname):
"""
Check whether or not a user has administrative rights for this bot.
This is a blocking function: use a coroutine to call it.
See pydle's documentation on blocking functionality for details.
"""
admin = False
# Check the WHOIS info to see if the source has identified with NickServ.
# This is a blocking operation, so use yield.
if nickname in ADMIN_NICKNAMES:
info = await self.whois(nickname)
print(info)
admin = info['identified']
return admin
async def on_message(self, target, source, message):
await super().on_message(target, source, message)
2020-10-18 13:53:02 -04:00
# Print Help
if message.startswith('!help {}'.format(target)):
await self.message(target, '] CnC globalforest__armeabi-v7a-debug-0.1 ')
await self.message(target, '!id - cnc user info'
2020-10-17 12:22:22 -04:00
# Tell a user if they are an administrator for this bot.
2020-10-18 13:53:02 -04:00
if message.startswith('!id {}'.format(target)):
2020-10-17 12:22:22 -04:00
admin = await self.is_admin(source)
if admin:
2020-10-18 13:53:02 -04:00
await self.message(target, 'You are an administrator. :)'.format(source))
2020-10-17 12:22:22 -04:00
else:
2020-10-18 13:53:02 -04:00
await self.message(target, 'You are NOT an administrator. :('.format(source))
2020-10-17 12:22:22 -04:00
2020-10-18 13:53:02 -04:00
def CnCApp():
2020-10-17 12:22:22 -04:00
cnc = ForestBot('client_' + get_random_string(5))
cnc.run(CNC_HOST, tls=False, tls_verify=False)
2020-10-18 13:53:02 -04:00
if __name__ == '__main__':
CnCApp()
2020-10-17 12:22:22 -04:00