diff --git a/.github/workflows/test_run.yaml b/.github/workflows/test_run.yaml new file mode 100644 index 0000000..4303477 --- /dev/null +++ b/.github/workflows/test_run.yaml @@ -0,0 +1,36 @@ +name: Test run Discord BOT + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + run-app: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + + steps: + - name: Check out the repository + uses: actions/checkout@v3 + + - name: Set up Python 3.11.4 + uses: actions/setup-python@v4 + with: + python-version: 3.11.4 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run bot.py + env: + TOKEN: ${{ secrets.TOKEN }} + run: | + python bot.py -github diff --git a/bot.py b/bot.py index c41a4d9..dbbba02 100644 --- a/bot.py +++ b/bot.py @@ -29,7 +29,13 @@ async def on_ready(): await bot.post_log_channel( g_PluginManager.num_plugins() ); await bot.wait_until_ready(); await g_PluginManager.CallHook( 'on_ready' ); - if gpGlobals.time() == 0: + + if gpGlobals.workflow(): + await g_PluginManager.CallHook( 'on_think' ); # Call on_think once + await bot.log_channel( "All tests ended, Shutting down bot." ); + await bot.close(); + exit(0); + elif gpGlobals.time() == 0: on_think.start() @bot.event @@ -66,12 +72,24 @@ async def on_reaction_add( reaction: discord.Reaction, user : discord.User ): async def on_reaction_remove( reaction: discord.Reaction, user : discord.User ): await g_PluginManager.CallHook( 'on_reaction_remove', reaction, user ); -Token_Name = 'dev' if gpGlobals.developer() else 'token'; -Token_Path = '{}\\{}.txt'.format( gpGlobals.abs(), Token_Name ); +Token: str; + +if gpGlobals.workflow(): + + Token = os.getenv( 'TOKEN' ); + +else: + + Token_Name = 'dev' if gpGlobals.developer() else 'token'; + + Token_Path = '{}{}.txt'.format( gpGlobals.abs(), Token_Name ); + + if not os.path.exists( Token_Path ): + print( 'File {} doesn\'t exists! Exiting...' ); + exit(1); + + Token_File = open( Token_Path, 'r' ).readlines(); -if not os.path.exists( Token_Path ): - print( 'File {} doesn\'t exists! Exiting...' ); - exit(1); + Token = Token_File[0]; -Token_File = open( Token_Path, 'r' ).readlines(); -bot.run( Token_File[0] ); +bot.run( Token ); diff --git a/plugins/main.py b/plugins/main.py index 85f60ae..2f458e7 100644 --- a/plugins/main.py +++ b/plugins/main.py @@ -54,12 +54,12 @@ class gpGlobals: @staticmethod def abs() -> str: '''Return absolute path value to the bot folder''' - return '{}\\'.format( os.path.abspath( "" ) ); + return '{}/'.format( os.path.abspath( "" ) ); @staticmethod def absp() -> str: '''Return absolute path value to the plugins folder''' - return '{}plugins\\'.format( gpGlobals.abs() ); + return '{}plugins/'.format( gpGlobals.abs() ); __time__ = 0; @staticmethod @@ -73,6 +73,12 @@ def developer() -> bool: '''Returns **True** If the bot has been run by using the ``-dev`` argument''' return gpGlobals.__developer__; + __git_workflow__ = True if '-github' in sys.argv else False; + @staticmethod + def workflow() -> bool: + '''App has been run from Github's workflows''' + return gpGlobals.__git_workflow__; + @staticmethod def should_think( var: int, next_think: int ) -> ( bool, int ): # type: ignore '''Returns whatever this is the time to think''' @@ -160,6 +166,10 @@ def __init__(self, *, intents: discord.Intents): self.tree = app_commands.CommandTree(self) async def setup_hook(self): + + if gpGlobals.workflow(): + return; + if gpGlobals.developer(): __MY_GUILD__ = discord.Object( id = self.LP() ); self.tree.clear_commands(guild=__MY_GUILD__) @@ -176,7 +186,12 @@ async def log_channel( self, message: str, arguments: list = [] ): '''Log to #bots-testing channel''' for __arg__ in arguments: message = message.replace( "{}", str( __arg__ ), 1 ) - return await self.get_channel( 1211204941490688030 ).send( message ); + + if gpGlobals.workflow(): + print( message ); + await self.get_channel( 1065791552485605446 ).send( message ); + else: + await self.get_channel( 1211204941490688030 ).send( message ); __pre_logs__:list[dict] = []; @@ -244,13 +259,19 @@ def num_plugins( self ) -> int: def __init__( self ): - PluginObject = gpUtils.jsonc( '{}\\plugins.json'.format( gpGlobals.abs() ) ); + PluginObject = gpUtils.jsonc( '{}plugins.json'.format( gpGlobals.abs() ) ); PluginData = PluginObject[ "plugins" ]; for plugin in PluginData: + if not "Author Name" in plugin: + plugin[ "Author Name" ] = "Mikk" + if not "Author Contact" in plugin: + plugin[ "Author Contact" ] = "https://github.com/Mikk155/" + if not plugin[ "Enable" ]: - bot.pre_log_channel( "Skipping disabled plugin \"{}\"".format( self.plugin_name( plugin ) )) + if not gpGlobals.developer(): + bot.pre_log_channel( "Skipping disabled plugin \"{}\"".format( self.plugin_name( plugin ) )) continue; try: @@ -277,7 +298,8 @@ def __init__( self ): self.fnMethods[ hook ].append( modulo ); - bot.pre_log_channel( msg ); + if not gpGlobals.developer(): + bot.pre_log_channel( msg ); except Exception as e: