-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathghist-botkeeper.py
131 lines (102 loc) · 3.44 KB
/
ghist-botkeeper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import argparse
import json
import logging
import os
from pathlib import Path
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv("ghist-bot.env")
from ghist.checks import (
SUPPORT_CHANNELS,
DOGS_CHANNELS,
DAILY_CHANNELS,
globally_block_dms,
)
from ghist.cogs.color import Color
from ghist.cogs.spelunkicon import Spelunkicon
from ghist.cogs.sync_ranking_icons import MossRankingIconSync
from ghist.cogs.mr_sync import MossrankingSync
from ghist.cogs.pronouns import Pronouns
from ghist.cogs.ushabti import Ushabti
from ghist.cogs.daily_channel_titles import DailyChannelTitles
TOKEN = os.environ["GHIST_BOT_TOKEN"]
def parse_config(config_path):
with config_path.open("r") as config_file:
data = json.load(config_file)
for guild, channels in data.get("support-channels", {}).items():
SUPPORT_CHANNELS[guild] = channels
DOGS_CHANNELS.update(set(data.get("dogs-channels", [])))
DAILY_CHANNELS.update(set(data.get("daily-channels", [])))
return data
class GhistBotkeeper(commands.Bot):
pass
class HelpCommand(commands.DefaultHelpCommand):
def add_indented_commands(self, commands, *, heading, max_size=None):
if not commands:
return
max_size = max_size or self.get_max_size(commands)
get_width = discord.utils._string_width
for command in commands:
name = command.name
if name == "help":
continue
width = max_size - (get_width(name) - len(name))
entry = "{0:<{width}} {1}".format(name, command.short_doc, width=width)
self.paginator.add_line(self.shorten_text(entry))
def get_ending_note(self):
command_name = self.invoked_with
return "Type {0}{1} command for more info on a command.\n".format(
self.context.clean_prefix, command_name
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--prefix", default="!", help="The prefix this bot uses on bot commands."
)
parser.add_argument(
"--config",
default=Path(__file__).absolute().parent / "ghist-bot-config.json",
type=Path,
help="Path to config file.",
)
args = parser.parse_args()
config = {}
if args.config.exists():
config = parse_config(args.config)
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
ghist = GhistBotkeeper(
command_prefix=args.prefix, help_command=HelpCommand(), intents=intents
)
# Cog Setup
ghist.add_cog(Color(ghist))
ghist.add_cog(Pronouns(ghist))
ghist.add_cog(Ushabti(ghist))
ghist.add_cog(Spelunkicon(ghist))
ghist.add_cog(DailyChannelTitles(ghist))
if config.get("mr-sync"):
ghist.add_cog(
MossrankingSync(
bot=ghist,
guild_id=config["mr-sync"]["guild-id"],
role_id=config["mr-sync"]["role-id"],
game_role_ids=config["mr-sync"].get("games", {}),
)
)
ghist.add_cog(
MossRankingIconSync(
bot=ghist,
guild_id=config["mr-sync"]["guild-id"],
)
)
# Global Checks
ghist.add_check(globally_block_dms)
ghist.run(TOKEN)
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
main()