diff --git a/cncbot.py b/cncbot.py new file mode 100644 index 0000000..1067c85 --- /dev/null +++ b/cncbot.py @@ -0,0 +1,50 @@ +import pydle +import random +import string + +CNC_HOST='dark.deflax.net' +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) + + # Tell a user if they are an administrator for this bot. + if message.startswith('!stats'): + admin = await self.is_admin(source) + + if admin: + await self.message(target, '{}: You are an administrator.'.format(source)) + else: + await self.message(target, '{}: You are not an administrator.'.format(source)) + +if __name__ == '__main__': + cnc = ForestBot('client_' + get_random_string(5)) + cnc.run(CNC_HOST, tls=False, tls_verify=False) + \ No newline at end of file diff --git a/main.py b/main.py index 3c9f7ed..32edf27 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,12 @@ # Import system modules -from random import randrange +#import trio +import asyncio +import random import sqlite3 # Import Kivy modules #from kivy.app import App +#from kivy.app import async_runTouchApp from kivymd.app import MDApp from kivy.lang import Builder @@ -22,8 +25,8 @@ from gpshelper import GpsHelper from settings import SampleBoxLayout from game import GameWidget -# MOTD -motd = """] +# Welcome message +MOTD = """] ] GlobalForest 0.1 by afx""" Builder.load_string(""" @@ -64,7 +67,7 @@ class MainApp(MDApp): def on_start(self): # Welcome - print(motd) + print(MOTD) self.theme_cls.primary_palette = 'BlueGray' @@ -79,9 +82,20 @@ class MainApp(MDApp): #self.search_menu = SearchPopupMenu() if __name__ == '__main__': + #asyncio.run(MainLoop()) #screen_manager = ScreenManager() #screen_manager.add_widget(ScreenOne(name="screen_one")) - #screen_manager.add_widget(ScreenTwo(name="screen_two")) - app = MainApp() - app.run() - + #screen_manager.add_widget(ScreenTwo(name="screen_two")) + + kivyapp = MainApp() + kivyapp.run() + #cnc = ForestBot('client_' + get_random_string(5)) + + #loop = asyncio.get_event_loop() + #loop.create_task( + # cnc.run(CNC_HOST, tls=False, tls_verify=False) + #) + #loop.run_until_complete( + # kivyapp.async_run() + #) + #loop.close() \ No newline at end of file diff --git a/requierments.txt b/requierments.txt index 726f39c..15cdc7d 100644 --- a/requierments.txt +++ b/requierments.txt @@ -1,4 +1,5 @@ +Kivy +pydle ffpyplayer sqlite_utils -Kivy mapview