Improved project file structure
This commit is contained in:
0
tests/custom/discord/src/modules/__init__.py
Normal file
0
tests/custom/discord/src/modules/__init__.py
Normal file
1
tests/custom/discord/src/modules/hello_world/__init__.py
Normal file
1
tests/custom/discord/src/modules/hello_world/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# imports:
|
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "hello-world",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"URL": "",
|
||||
"CopyrightDate": "",
|
||||
"CopyrightName": "",
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.7.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.7.0.post1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
"linux": ""
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "hello_world.main",
|
||||
"EntryPoint": "hello-world",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
import discord
|
||||
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events.on_ready_abc import OnReadyABC
|
||||
from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class OnReadyEvent(OnReadyABC):
|
||||
|
||||
def __init__(self, logger: LoggerABC, bot: DiscordBotServiceABC):
|
||||
OnReadyABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
def _log(self, _t: str, _o: object, _type: type = None):
|
||||
self._logger.debug(__name__, f'{_t} {_o} {_type}')
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.info(__name__, 'Hello World')
|
||||
for g in self._bot.guilds:
|
||||
self._log('-Guild', g, type(g))
|
||||
for r in g.roles:
|
||||
self._log('--Role', r, type(r))
|
||||
for rm in r.members:
|
||||
self._log('---Rolemember', rm, type(rm))
|
||||
|
||||
for m in g.members:
|
||||
self._log('--Member', m, type(m))
|
||||
for mr in m.roles:
|
||||
self._log('--Memberole', mr, type(mr))
|
||||
for rm in mr.members:
|
||||
self._log('---Rolemember', rm, type(rm))
|
||||
|
||||
select = self._bot.guilds.select(lambda guild: (guild.name, guild.id))
|
||||
self._logger.warn(__name__, f'Does cpl.query select work? {select}')
|
||||
select_many = self._bot.guilds.select_many(lambda guild: guild.roles).where(lambda role: role.name == "Tester").first()
|
||||
self._logger.warn(__name__, f'Does cpl.query select_many work? {select_many}')
|
@@ -0,0 +1,12 @@
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events.on_ready_abc import OnReadyABC
|
||||
|
||||
|
||||
class OnReadyTestEvent(OnReadyABC):
|
||||
|
||||
def __init__(self, logger: LoggerABC):
|
||||
OnReadyABC.__init__(self)
|
||||
self._logger = logger
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.info(__name__, 'Test second on ready')
|
28
tests/custom/discord/src/modules/hello_world/ping_command.py
Normal file
28
tests/custom/discord/src/modules/hello_world/ping_command.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.command.discord_command_abc import DiscordCommandABC
|
||||
from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class PingCommand(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
|
||||
@commands.hybrid_command()
|
||||
async def ping(self, ctx: Context):
|
||||
self._logger.debug(__name__, f'Received command ping {ctx}')
|
||||
self._logger.info(__name__, f'Bot name {self._bot.user.name}')
|
||||
self._logger.trace(__name__, f'Finished ping command')
|
||||
await ctx.send('Pong')
|
@@ -0,0 +1,31 @@
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.command.discord_command_abc import DiscordCommandABC
|
||||
from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class PurgeCommand(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
|
||||
@commands.hybrid_command()
|
||||
async def purge(self, ctx: Context):
|
||||
self._logger.debug(__name__, f'Received command ping {ctx}')
|
||||
self._logger.info(__name__, f'Bot name {self._bot.user.name}')
|
||||
self._logger.trace(__name__, f'Finished ping command')
|
||||
await ctx.channel.purge()
|
||||
if ctx.interaction is None:
|
||||
return
|
||||
await ctx.interaction.response.send_message('Purged this channel xD')
|
Reference in New Issue
Block a user