This repository has been archived by the owner on Jan 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
98 lines (74 loc) · 2.86 KB
/
main.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
"""main bot script"""
import discord
import discord.utils
import cmdtools
import lyricsgenius
import asyncpraw
import datetime
import web
import config
from library import utility
from library.music import Music
class Bot(discord.Client):
"""BatChest bot instance"""
def __init__(self):
self.genius = lyricsgenius.Genius(config.GENIUS_TOKEN)
self.reddit = asyncpraw.Reddit(
client_id=config.REDDIT_CLIENT_ID,
client_secret=config.REDDIT_CLIENT_SECRET,
user_agent="Reddit?! Haha Wowzers!!11! BatChest",
)
self.music = Music(self)
super().__init__()
def get_voice(self) -> discord.VoiceClient:
"""get bot voice client"""
return discord.utils.get(self.voice_clients, guild=self.get_guild(config.GUILD))
@classmethod
def is_user_in_vc(cls, member: discord.Member) -> bool:
"""check if user is in any voice channel"""
return not member.voice
def is_in_vc(self) -> bool:
"""check if client is in any voice channel"""
return not self.get_voice()
def check_user_vc(self, user: discord.Member) -> bool:
"""check if user is in same voice channel as the client"""
return (self.get_voice().channel.id if self.get_voice() is not None else 0) == (
user.voice.channel.id if user.voice is not None else 1
)
async def on_ready(self):
"""called when bot client is ready"""
self.start_time = datetime.datetime.utcnow()
voice = self.get_voice()
if voice:
await voice.disconnect()
self.loop.create_task(self.music.run())
await self.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name=f"{config.PREFIXES['general']}help",
)
)
print("I'm Ready BatChest")
async def on_disconnect(self):
"""called when client disconnected"""
voice = self.get_voice()
if voice:
await voice.disconnect()
async def on_message(self, message):
"""called when new guild message created"""
if message.author.bot or isinstance(message.channel, discord.channel.DMChannel):
return
if message.guild.id == config.GUILD:
for command in utility.get_commands():
cmdobj = utility.load_command(command)
if cmdobj and command in config.PREFIXES:
cmd = cmdtools.AioCmd(message.content, prefix=config.PREFIXES[command])
if cmd.name:
await cmdobj.group.run(
cmd, attrs={"message": message, "client": self}
)
if __name__ == "__main__":
print(f"Starting BatChest v{config.Version(0)} ...")
bot = Bot()
web.server.start()
bot.run(config.TOKEN)