-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae05fa9
commit 762281d
Showing
3 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
import datetime | ||
from functools import wraps | ||
import traceback | ||
import discord | ||
from discord.ext import commands | ||
from dotenv import load_dotenv | ||
from os import getenv | ||
|
||
def excepter(func): | ||
load_dotenv() | ||
CHANNEL_TRACEBACK_ID = getenv('CHANNEL_TRACEBACK_ID') | ||
|
||
|
||
def excepter(func, *, _channel_id=None): | ||
@wraps(func) | ||
async def wrapped(self, *args, **kwargs): | ||
try: | ||
return await func(self, *args, **kwargs) | ||
except Exception as e: | ||
orig_error = getattr(e, 'original', e) | ||
message = ''.join(traceback.TracebackException.from_exception(orig_error).format()) | ||
appinfo = await self.bot.application_info() | ||
await appinfo.owner.send(f'```python\n{message}\n```') | ||
error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format()) | ||
|
||
channel_id = _channel_id or CHANNEL_TRACEBACK_ID | ||
if len(args) >= 1 and isinstance(args[0], discord.Interaction): | ||
interaction: discord.Interaction = args[0] | ||
channel = interaction.client.get_channel(channel_id) | ||
else: | ||
bot: commands.Bot = self.bot | ||
channel = bot.get_channel(channel_id) | ||
|
||
if channel: | ||
embed = discord.Embed() | ||
embed.add_field(name='class', value=self.__class__.__name__) | ||
embed.add_field(name='function', value=func.__name__) | ||
embed.add_field(name='datetime', value=datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S.%f')) | ||
await channel.send(f'```python\n{error_msg}\n```', embed=embed) | ||
return wrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from functools import wraps | ||
from datetime import datetime | ||
import discord | ||
from discord.ext import commands | ||
from dotenv import load_dotenv | ||
from os import getenv | ||
|
||
load_dotenv() | ||
CHANNEL_LOG_ID = getenv('CHANNEL_LOG_ID') | ||
|
||
|
||
def dpylogger(func, *, _channel_id=None): | ||
@wraps(func) | ||
async def wrapped(self, *args, **kwargs): | ||
channel_id = _channel_id or CHANNEL_LOG_ID | ||
if len(args) >= 1 and isinstance(args[0], discord.Interaction): | ||
interaction: discord.Interaction = args[0] | ||
channel = interaction.client.get_channel(channel_id) | ||
else: | ||
bot: commands.Bot = self.bot | ||
channel = bot.get_channel(channel_id) | ||
|
||
if channel: | ||
content = ' '.join((self.__class__.__name__, func.__name__, datetime.now().strftime('%Y/%m/%d %H:%M:%S.%f'))) | ||
await channel.send(content) | ||
await func(self, *args, **kwargs) | ||
return wrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setup( | ||
name='Daug', | ||
version='2023.2.28.1', | ||
version='2023.12.3.1', | ||
author='Discord Bot Portal JP', | ||
author_email='[email protected]', | ||
description='discord.py を利用した Discord Bot 向け機能拡張ライブラリ', | ||
|
@@ -18,10 +18,11 @@ | |
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
'Programming Language :: Python :: 3.11', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
], | ||
install_requires=[ | ||
'discord.py >= 2.1.1', | ||
'discord.py >= 2.3.2', | ||
], | ||
) |