-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
194 lines (167 loc) · 7.51 KB
/
app.py
File metadata and controls
194 lines (167 loc) · 7.51 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#-*- coding: utf-8 -*-
import discord
from os import getenv
import logging
import sys, traceback
import random
import dbinteraction
import json
import requests
from discord.ext import commands
import asyncio
from subprocess import call
import schedule
from datetime import datetime
import watchdoggo
from apscheduler.schedulers.background import BackgroundScheduler
import pytz
commandcnt = 0
dog = watchdoggo.Doggo
bot = commands.AutoShardedBot(command_prefix='n$', pm_help=False)
logging.basicConfig(level=logging.INFO, \
format='[%(asctime)s] %(levelname)s - [%(name)s] %(message)s')
log = logging.getLogger(__name__)
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def stats():
global commandcnt
print("Stats INIT")
print("dog OK")
dog.gather(len(bot.guilds), len(bot.users), dbinteraction.dbexec("SELECT COUNT(*) FROM serverdata"), commandcnt)
dog.update()
print("Dog done")
commandcnt = 0
def servping():
call(["curl", "-X POST", "--data" ,f"time={datetime.now().timestamp()}&servs{len(bot.guilds)}", "http://newe.space/konata/status/check"])
print('[[[[[EMITED SERVER PING]]]]]')
sched = BackgroundScheduler(daemon=True, timezone="Europe/Paris")
sched.add_job(stats, 'cron', hour='1', minute='1')
sched.add_job(servping, 'cron', minute='10')
sched.start()
async def autogmchange():
try:
await bot.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(bot.guilds)} servers | n$help", url='https://twitch.tv/newe1337', state="Doing bot things", details="skrrt skrrt"))
except:
pass
await asyncio.sleep(300)
## Events
@bot.event
async def on_ready():
guilds=[]
ard=random.randint(1,8)
print(f"Logged in as {bot.user}, d.py V{discord.__version__}")
for g in bot.guilds:
guilds.append(g.name)
print("-----------------------------------------------------\n\
Connected to: {}\n-----------------------------------------------------".format(" | ".join(guilds)))
bt=bot.loop.create_task(autogmchange())
@bot.event
async def on_message(message):
await bot.process_commands(message)
@bot.event
async def on_command(ctx):
global commandcnt
commandcnt+=1
print(f"{bcolors.WARNING} [COMMAND] | {ctx.message.author} : {ctx.message.clean_content[2:]} [{commandcnt}] {bcolors.ENDC}")
dog.ddNewCommand()
call(["curl", "--data" ,f"content=**__{ctx.message.author}__** : `{ctx.message.clean_content[2:]}`&username=Commande exécutée&avatar_url=https://cdn.discordapp.com/attachments/440454225961680896/440454482657017856/goodjob.gif", dbinteraction.dbexec("comhook", log=True)])
@bot.event
async def on_guild_join(guild):
try:
em = discord.Embed(title="Hello ໒( ●ᴥ ●)ʋ", color=discord.Color(0xff0000))
em.set_thumbnail(url="https://cdn.discordapp.com/avatars/366632492590956544/e33fb154663f5a63138d934224b47c7d.png?size=1024")
em.add_field(name="The name's Konata", value="A capable and experimental discord bot!\n\
To see the list of my commands, type **__n$__help** <:NWKonataThumbsUp:445210207597887489>\n\
If you like what i do, please consider [voting for this bot](https://discordbots.org/bot/366632492590956544) and suggest this bot around, it would help me a lot, thanks (\*´▽`\*)!")
ch = guild.system_channel
print(f"channel set: {ch}")
if not ch:
print("not ch")
for c in guild.text_channels:
if not c.permissions_for(guild.me).send_messages:
print("ch test")
continue
ch = c
print("ch found")
break
print("done")
await ch.send(embed=em)
try:
payload = { "embeds": [ { "title": "Nouveau serveur", "color": 11468544, "footer": { "icon_url": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3f/3fabd870d12b4301114bd6ffe9267b8eb560036d_full.jpg", "text": f"Total: {len(bot.guilds)} serveurs" }, "thumbnail": { "url": guild.icon }, "fields": [ { "name": "Nom", "value": guild.name, "inline": True }, { "name": "Membres", "value": len(guild.members), "inline": True }, { "name": "ID", "value": guild.id, "inline": False } ]} ] }
headers = { 'Content-Type': 'application/json' }
response = requests.post(dbinteraction.dbexec("serverhook", log=True), data=json.dumps(payload), headers=headers)
return response
except(Exception) as e:
print(e)
call(["curl", "--data" ,f"content=Nom: *{guild.name}*\nID : `{guild.id}`\n Total: {len(bot.guilds)} serveurs&username=Nouveau serveur&avatar_url=https://cdn.discordapp.com/attachments/440454225961680896/440454482657017856/goodjob.gif", dbinteraction.dbexec("serverhook", log=True)])
except(Exception) as e:
print(e)
@bot.event
async def on_guild_remove(guild):
try:
payload = { "embeds": [ { "title": "Nouveau serveur", "color": 16711684, "footer": { "icon_url": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3f/3fabd870d12b4301114bd6ffe9267b8eb560036d_full.jpg", "text": f"Total: {len(bot.guilds)} serveurs" }, "thumbnail": { "url": guild.icon }, "fields": [ { "name": "Nom", "value": guild.name, "inline": True }, { "name": "Membres", "value": len(guild.members), "inline": True }, { "name": "ID", "value": guild.id, "inline": False } ]} ] }
headers = { 'Content-Type': 'application/json' }
response = requests.post(dbinteraction.dbexec("serverhook", log=True), data=json.dumps(payload), headers=headers)
return response
except:
print('guild leave, ms fail')
call(["curl", "--data" ,f"content=Nom: *{guild.name}*\nID : `{guild.id}`\n Total: {len(bot.guilds)} serveurs&username=Serveur quitté&avatar_url=https://cdn.discordapp.com/attachments/440454225961680896/440454482657017856/goodjob.gif", dbinteraction.dbexec("serverhook", log=True)])
@bot.event
async def on_member_join(member):
a=dbinteraction.dbexec("SELECT role FROM serverdata WHERE server_id = ?", (member.guild.id,))
if a!=None:
role = discord.utils.get(member.guild.roles, id=a)
await member.add_roles(role, reason="[KONA] Autorole")
@bot.event
async def on_member_ban(guild, user):
print(f"**{user.name}** has been banned!")
## Core commands
@bot.command(hidden=True)
@commands.is_owner()
async def load(ctx, extension_name : str):
try:
bot.load_extension(extension_name)
except (AttributeError, ImportError) as e:
await ctx.message.add_reaction('🈲')
await ctx.send(f"```py\n{type(e).__name__}: {str(e)}\n```")
return
await ctx.message.add_reaction('🉑')
@bot.command(hidden=True)
@commands.is_owner()
async def unload(ctx, extension_name : str):
try:
bot.unload_extension(extension_name)
except (AttributeError, ImportError) as e:
await ctx.message.add_reaction('🈲')
await ctx.send(f"```py\n{type(e).__name__}: {str(e)}\n```")
return
await ctx.message.add_reaction('🉑')
@bot.command(aliases=["rl"], hidden=True)
@commands.is_owner()
async def reload(ctx, extension_name : str):
try:
bot.unload_extension(extension_name)
bot.load_extension(extension_name)
except (AttributeError, ImportError) as e:
await ctx.message.add_reaction('🈲')
await ctx.send(f"```py\n{type(e).__name__}: {str(e)}\n```")
return
await ctx.message.add_reaction('🉑')
initial_extensions = ['simple', "admin", "osu", "audio", "anime", "owner", "dbotsapi", "servmgmt"]
if __name__ == "__main__":
for extension in initial_extensions:
try:
bot.load_extension(extension)
except Exception as e:
exc = f"{type(e).__name__}: {e}"
print(f"Failed to load extension `{extension}\n{exc}`")
print(f"{bcolors.OKGREEN}Logging in...!{bcolors.ENDC}")
bot.run(getenv('DISCORD_TOKEN')) #Heroku login
#dbinteraction.dbexec("dstk", log=True) <- local login