-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot-pixie-instance.py
More file actions
executable file
·153 lines (138 loc) · 6.38 KB
/
bot-pixie-instance.py
File metadata and controls
executable file
·153 lines (138 loc) · 6.38 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
import aiohttp
import asyncio
import datetime
import discord
import logging
import subprocess
import time
import traceback
import websockets
import sys
import os
from discord.ext import commands
from discord.utils import get
from pixie_function import *
import config as cfg
listmodules = readData('main')
root_dir = os.path.dirname(os.path.abspath(__file__))
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Navigation Pixie', intents=intents)
#bot = commands.Bot(command_prefix='!', description='Navigation Pixie', intents=intents)
bot.remove_command('help')
@bot.event
async def on_ready():
chan = bot.get_channel(cfg.botlog_chan)
logging.info('NAVIGATIONPIXIE > Logged in as {} with ID {}'.format(bot.user.name, bot.user.id))
await chan.send('Connected ! Loading modules...')
#Loading core module first
try:
await bot.load_extension('modules.core')
except ImportError:
await chan.send('<@{}> Failed to load core module ! Can\'t init bot instance !'.format(cfg.bot_ownerid))
logging.error('NAVIGATIONPIXIE > Failed to load core module ! Can\'t init bot instance !')
await bot.close()
sys.exit()
except SyntaxError:
if module == 'core':
await chan.send('<@{}> Syntax error on core module ! Can\'t init bot instance !'.format(cfg.bot_ownerid))
logging.error('NAVIGATIONPIXIE > Syntax error on core module ! Can\'t init bot instance !')
await bot.close()
sys.exit()
#Loading modules
for module in listmodules:
if (listmodules[module]["default"] == "loaded" or listmodules[module]["default"] == "global"):
try:
await bot.load_extension('modules.' + module)
except ImportError:
await chan.send('```py\n%s\n```' % traceback.format_exc())
logging.error('NAVIGATIONPIXIE > Failed to load module {}.'.format(module))
except SyntaxError:
await chan.send('```py\n%s\n```' % traceback.format_exc())
logging.warning('NAVIGATIONPIXIE > Bad module : {}'.format(module))
await chan.send('Ready !')
logging.info('NAVIGATIONPIXIE > Connected !')
@bot.event
async def on_resumed():
logging.warning('NAVIGATIONPIXIE > Session resumed...')
# @bot.event
# async def on_command():
@bot.event
async def on_command_error(ctx, error):
if not str(error) == 'Command "' + ctx.invoked_with + '" is not found':
await bot.get_channel(cfg.botlog_chan).send('<@{}>'.format(cfg.bot_ownerid))
embed = discord.Embed(title=':x: Command Error', colour=0x992d22, timestamp=datetime.datetime.utcnow())
embed.description = '```py\n%s\n```' % traceback.format_exc()
embed.add_field(name='Error', value=error)
embed.add_field(name='Server', value=ctx.message.guild.name)
embed.add_field(name='Channel', value='<#{}>'.format(ctx.message.channel.id))
embed.add_field(name='User', value='<@{}>'.format(ctx.message.author.id))
embed.add_field(name='Command', value='`{}`'.format(ctx.message.clean_content))
embed.set_footer(text='on_command_error')
await bot.get_channel(cfg.botlog_chan).send(embed=embed)
@bot.event
async def on_error(event, *args, **kwargs):
await bot.get_channel(cfg.botlog_chan).send('<@{}>'.format(cfg.bot_ownerid))
embed = discord.Embed(title=':x: Event Error', colour=0xe74c3c, timestamp=datetime.datetime.utcnow())
embed.description = '```py\n%s\n```' % traceback.format_exc()
embed.add_field(name='Event', value=event)
embed.set_footer(text='on_error')
await bot.get_channel(cfg.botlog_chan).send(embed=embed)
#MISC
@bot.command(pass_context=True)
async def restart(ctx):
if ctx.message.author.id == cfg.bot_ownerid:
logging.info('NAVIGATIONPIXIE > Restart')
await ctx.send('I`ll be back !')
await bot.close()
@bot.command(pass_context=True)
async def quit(ctx):
if ctx.message.author.id == cfg.bot_ownerid:
logging.info('NAVIGATIONPIXIE > SystemExit')
await ctx.send('Goodbye !')
await bot.close()
sys.exit()
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('!'):
#logging commands only (including unknown commands)
logging.info('{0.guild.name} > {0.content}'.format(message))
if bot.user.mentioned_in(message):
try:
emoji = bot.get_emoji(443086928716496897)
await message.add_reaction(emoji)
except:
await bot.get_channel(cfg.botlog_chan).send('```py\n%s\n```' % traceback.format_exc())
await bot.process_commands(message)
@bot.event
async def on_guild_join(guild):
em = discord.Embed(title=guild.name, type='rich', description='Total : {}'.format(str(len(bot.servers))), colour=0x23d160, timestamp=datetime.datetime.utcnow())
em.set_author(name='New server joined !', icon_url=guild.icon_url)
em.set_thumbnail(url=guild.icon_url)
em.add_field(name='ID', value=guild.id)
em.add_field(name='Region', value=guild.region)
em.add_field(name='Owner', value='<@{}>'.format(guild.owner.id))
em.add_field(name='Members', value=guild.member_count)
em.add_field(name='Created at', value=guild.created_at)
roles = ''
for e in guild.role_hierarchy:
roles = roles + e.name + ' '
em.add_field(name='Roles', value=roles)
em.add_field(name='2FA', value=guild.mfa_level)
await bot.get_channel(cfg.botlog_chan).send(embed=em)
@bot.event
async def on_guild_remove(guild):
em = discord.Embed(title=guild.name, type='rich', description='Total : {}'.format(str(len(bot.servers))), colour=0xe74c3c, timestamp=datetime.datetime.utcnow())
em.set_author(name='Server removed !', icon_url=guild.icon_url)
em.set_thumbnail(url=guild.icon_url)
em.add_field(name='ID', value=guild.id)
em.add_field(name='Region', value=guild.region)
em.add_field(name='Owner', value='<@{}>'.format(guild.owner.id))
em.add_field(name='Members', value=guild.member_count)
em.add_field(name='Created at', value=guild.created_at)
em.add_field(name='2FA', value=guild.mfa_level)
await bot.get_channel(cfg.botlog_chan).send(embed=em)
logging.basicConfig(format='%(asctime)s | [%(levelname)s] | %(message)s', datefmt='%m/%d/%Y - %H:%M:%S', filename=root_dir + '/latest.log',level=logging.INFO)
bot.run(cfg.token)