forked from The-Order-of-The-Boar/Boar-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
107 lines (68 loc) · 2.83 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
##############################################################################################
import discord
from datetime import datetime
import sys
from psycopg2.errors import ForeignKeyViolation
client = discord.Client(intents=discord.Intents.all())
from commands import messages
from commands import rank
from commands import server
from commands import misc
from core import comms
#################################Start#####################################################
@client.event
async def on_ready():
print("On")
print(datetime.now())
#################################Guild Join#####################################################
@client.event
async def on_guild_join(guild):
server.AddServer(guild.id,guild.text_channels)
#################################New Member##################################################
@client.event
async def on_member_join(member):
server_id = member.guild.id
#Welcome message if exists
welcome = server.GetWelcome(server_id)
if (not welcome["message"] == None):
#Welcome image in the capital
image = None
if(member.guild.id == 272166101025161227):
misc.WelcomeImage(member.nick,member.avatar_url,member.guild.id)
image=discord.File(f"images/{member.nick}.png")
welcome["message"] = welcome["message"].replace("<mention>",member.mention)
await client.get_channel(welcome["channel"]).send(welcome["message"],file=image)
#Autorole if exists
role_id = server.getAutorole(server_id)
if (not role_id == None):
guild = client.get_guild(server_id)
role = guild.get_role(role_id)
await member.add_roles(role)
#################################Message#####################################################
@client.event
async def on_message(message):
try:
messages.CountMessage(message.guild.id)
if(message.channel.id != 770107741585932339):
char_amount = len(message.content) - message.content.count(" ")
rank.countPoints(message.guild.id,message.author.id,char_amount)
except ForeignKeyViolation:
print("Reinvite the bot to the server!")
await message.channel.send("Reinvite the bot to the server!")
sys.exit()
#Ignores bot commands and rank
if message.author.bot:
return
await comms.ParseCommand(message,client)
@client.event
async def on_message_delete(message):
messages.UncountMessage(message)
#################################Other Events################################################
##############################################################################################
from os import environ
token = ""
if("DYNO" in environ):
token = environ['TOKEN']
else:
token = open("localToken.txt", 'r',encoding="utf-8").read()
client.run(token)