Skip to content

Commit

Permalink
test workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk155 committed Oct 7, 2024
1 parent 4c4067e commit 9b3c52c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 14 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test_run.yaml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 26 additions & 8 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
34 changes: 28 additions & 6 deletions plugins/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'''
Expand Down Expand Up @@ -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__)
Expand All @@ -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] = [];

Expand Down Expand Up @@ -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:
Expand All @@ -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:

Expand Down

0 comments on commit 9b3c52c

Please sign in to comment.