-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
107 lines (89 loc) · 3.25 KB
/
bot.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
'''
Winter-Song!
by Neophyte#5556 (Noble)
'''
import os
import discord
import asyncio
from discord.ext import commands
from ext.context import CustomContext
import psutil
import re
import json
from collections import defaultdict
import datetime
import aiohttp
class NewBot(commands.Bot):
'''
A Bot Made by ~ Neophyte#5556
'''
mentions_transforms = {
'@everyone': '@\u200beveryone',
'@here': '@\u200bhere'
}
mention_pattern = re.compile('|'.join(mentions_transforms.keys()))
def __init__(self, **attrs):
super().__init__(command_prefix = self.get_pre)
self.session = aiohttp.ClientSession(loop = self.loop)
self._extentions = [x.replace('.py', '') for x in os.listdir('cogs') if x.endswith('.py')]
self.remove_command('help')
self.process = psutil.Process()
self.commands_used = defaultdict(int)
self.load_extensions()
def load_extensions(self, cogs = None, path = 'cogs.'):
'''Loading the Extentions ;)'''
for extension in cogs or self._extentions:
try:
self.load_extension('{0}{1}'.format(path, extension))
print('Loaded Extention: {}'.format(extension))
except Exception as e:
print('CannotLoad: {0}\n'
'{type(e).__name__}: {1}'.format(extension, e))
@staticmethod
async def get_pre(bot, message):
'''GET THE PREFIX'''
with open('data/config.json') as f:
prefix = json.load(f).get('PREFIX')
return os.environ.get('PREFIX') or prefix or 'r. '
def restart(self):
os.exev(sys.executable, ['python'] + sys.argv)
@classmethod
def init(bot, token = None):
'''RUN THE BOT'''
amibot = bot()
with open('data/config.json') as f:
config = json.load(f)
if config["TOKEN"] == "your_token_here":
token = os.environ.get("TOKEN")
token = "{}".format(token)
else:
token = config["TOKEN"]
try:
amibot.run(token, bot = True, reconnect = True)
except Exception as e:
print(e)
async def on_connect(self):
print('-------------\n'+ 'Winter-Song Logged in!')
async def on_ready(self):
'''SET THE UPTIME'''
self.uptime = datetime.datetime.utcnow()
#+str(len(self.guilds))+ ,_ count broken placeholder 670
await self.change_presence(activity = discord.Game(name="w!help | [670] | update: Apex | Broken fixes soon.."))
async def on_command(self, ctx):
cmd = ctx.command.qualified_name.replace(' ', '_')
self.commands_used[cmd] +=1
async def process_commands(self, message):
'''Utilizing the CustomContext subclass'''
ctx = await self.get_context(message, cls = CustomContext)
if ctx.command is None:
return
await self.invoke(ctx)
async def on_message(self, message):
'''Ignore commands by self'''
if message.author.id == self.user.id or message.author.bot == True:
return
await self.process_commands(message)
def get_server(self, id):
return discord.utils.get(self.guilds, id = id)
if __name__ == '__main__':
NewBot.init()