generated from DiscordBotPortalJP/discordpy-startup
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from DiscordBotPortalJP/refactor
refactor
- Loading branch information
Showing
23 changed files
with
134 additions
and
101 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
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 +1 @@ | ||
discordbot: python discordbot.py | ||
web: python main.py |
Empty file.
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
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
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,6 @@ | ||
from dotenv import load_dotenv | ||
from os import getenv | ||
|
||
load_dotenv() | ||
|
||
TOKEN = getenv('DISCORD_BOT_TOKEN') |
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,24 @@ | ||
""" | ||
役職編成の辞書 | ||
村: 村人 | ||
狼: 人狼 | ||
占: 占い師 | ||
""" | ||
|
||
# シンプル編成(仮) | ||
simple = { | ||
4: '村村狼占', | ||
5: '村村狼狼占', | ||
6: '村村村狼狼占', | ||
7: '村村村村狼狼占', | ||
8: '村村村村村狼狼占', | ||
9: '村村村村村村狼狼占', | ||
10: '村村村村村村狼狼狼占', | ||
11: '村村村村村村村狼狼狼占', | ||
12: '村村村村村村村村狼狼狼占', | ||
13: '村村村村村村村村村狼狼狼占', | ||
14: '村村村村村村村村村村狼狼狼占', | ||
15: '村村村村村村村村村村村狼狼狼占', | ||
16: '村村村村村村村村村村村狼狼狼狼占', | ||
} |
This file was deleted.
Oops, something went wrong.
Empty file.
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,36 @@ | ||
import traceback | ||
from discord.ext import commands | ||
from utils.errors import PermissionNotFound, NotGuildChannel, NotDMChannel | ||
|
||
|
||
class HandleErrorCog(commands.Cog): | ||
def __init__(self, bot: commands.Bot): | ||
self.bot = bot | ||
|
||
@commands.Cog.listener() | ||
async def on_command_error(ctx, error: commands.CommandError): | ||
"""エラーハンドリング""" | ||
|
||
if isinstance(error, commands.CheckFailure): | ||
return | ||
|
||
if isinstance(error, PermissionNotFound): | ||
await ctx.send('コマンドを実行する権限がありません') | ||
return | ||
|
||
if isinstance(error, NotGuildChannel): | ||
await ctx.send('サーバー内でのみ実行できるコマンドです') | ||
return | ||
|
||
if isinstance(error, NotDMChannel): | ||
await ctx.send('DM内でのみ実行できるコマンドです') | ||
return | ||
|
||
orig_error = getattr(error, "original", error) | ||
error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format()) | ||
error_msg = "```py\n" + error_msg + "\n```" | ||
await ctx.send(error_msg) | ||
|
||
|
||
async def setup(bot: commands.Bot) -> None: | ||
await bot.add_cog(HandleErrorCog(bot)) |
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
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
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
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,34 @@ | ||
import discord | ||
from discord.ext import commands | ||
from application.game import Game | ||
from constants.discord import TOKEN | ||
|
||
extensions = [ | ||
'handle_error', | ||
'players', | ||
'status', | ||
'vote', | ||
] | ||
|
||
|
||
class WerewolfBot(commands.Bot): | ||
def __init__(self): | ||
super().__init__( | ||
command_prefix=commands.when_mentioned_or('$'), | ||
intents=discord.Intents.all(), | ||
) | ||
|
||
async def setup_hook(self): | ||
for extension in extensions: | ||
await self.load_extension(f'extensions.{extension}') | ||
# await self.tree.sync() | ||
|
||
|
||
def main(): | ||
bot = WerewolfBot() | ||
bot.game = Game() | ||
bot.run(TOKEN) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 +1,2 @@ | ||
discord.py[voice]>=1.4.1 | ||
discord.py[voice]>=2.3.1 | ||
dotenv |
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 +1 @@ | ||
python-3.8.5 | ||
python-3.11.6 |
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
Empty file.
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,12 @@ | ||
import discord | ||
|
||
class PermissionNotFound(discord.DiscordException): | ||
pass | ||
|
||
|
||
class NotGuildChannel(discord.DiscordException): | ||
pass | ||
|
||
|
||
class NotDMChannel(discord.DiscordException): | ||
pass |