-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
154 lines (123 loc) · 4.56 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
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
#General imports
import discord
from discord.ext import commands
import asyncio
import json
import datetime
import threading
import os
#Import Modules
import cogs.general
import cogs.fun
import cogs.mod
import cogs.catfacts
import cogs.testing
dcnbotVersion = "0.1.2"
if not os.path.isfile('data/warns/warns.dat'):
with open('data/warns/warns.dat', 'w') as f:
data = {}
json.dump(data, f)
async def decayWarn():
dataFile = 'data/warns/warns.dat'
data = {}
with open(dataFile, 'r', encoding='utf8') as f:
data = json.load(f)
print(data)
print('closed')
for key, value in data.items():
print (key, value)
if(int(value) < 1000):
temp = int(value) - 10
if(int(temp) <= 0):
print("They're already at the lowest")
data[key] = 0
else:
data[key] = int(value) - 10
if(int(data[key]) < 0):
data[key] = 0
print("decay 10 points from {0}".format(key))
with open(dataFile, 'w', encoding='utf8') as f:
print("saving new data")
json.dump(data, f)
# 86400 = day
# threading.Timer(60, decayWarn).start()
thr.start()
#Endif
thr = threading.Timer(86400, decayWarn)
#Load the config file and assign it to a variable.
with open('./config.json', 'r') as c_json:
config = json.load(c_json)
description = '''dcnbotPy is written in Python. Version {}'''.format(dcnbotVersion)
#Assign the prefix.
prefix = config["prefix_settings"]["prefix"]
#Check if prefix includes a spacer (example : dcn <command> instead of dcn<command>)
if config["prefix_settings"]["use_space"] == True:
prefix = prefix + ' '
#Create bot
bot = commands.Bot(command_prefix=prefix, description=description)
#Create variable for time of startup.
tu = datetime.datetime.now()
@bot.event
async def on_ready():
print('Logged in as ')
print(bot.user.name)
print(bot.user.id)
print('Bot prefix is set to ' + prefix)
print('-------------')
# await bot.change_presence(game=discord.Game(name='with systemd'))
if config["default_presence"] == "":
game = 'with systemd'
else:
game = config["default_presence"]
await bot.change_presence(game=discord.Game(name=game, type=0))
await decayWarn()
@bot.event
async def on_member_ban(self, member):
log_chan = config['log_channel']
chan_id = 0
for i in channels:
if log_chan in i.name:
chan_id = i
print('Channel Name is ' + chan_id.name)
isNotBot = false
def check(msg):
if (msg.author == self.bot.user):
isNotBot = false
else:
isNotBot = true
return isNotBot
initialMessage = await bot.send_message(log_chan, 'User **{0} : {1}** was banned for reason :\n***{2}***\nIf you were the moderator who banned this user, please reply in this channel with a reason for the ban.'.format(member.name, member.id, "unknown"))
reason = await bot.wait_for_message(channel=log_chan, check=check)
if(isNotBot == true):
return await bot.edit_message(initialMessage, 'User **{0} : {1}** was banned for reason :\n***{2}***\n\nBanned by : **{3}**'.format(member.name, member.id, reason, moderator.name))
@bot.command()
async def uptime():
"""Check bot uptime."""
global tu
await bot.say(timedelta_str(datetime.datetime.now() - tu))
#Convert uptime to a string.
def timedelta_str(dt):
days = dt.days
hours, r = divmod(dt.seconds, 3600)
minutes, sec = divmod(r, 60)
if minutes == 1 and sec == 1:
return '{0} days, {1} hours, {2} minute and {3} second.'.format(days,hours,minutes,sec)
elif minutes > 1 and sec == 1:
return '{0} days, {1} hours, {2} minutes and {3} second.'.format(days,hours,minutes,sec)
elif minutes == 1 and sec > 1:
return '{0} days, {1} hours, {2} minute and {3} seconds.'.format(days,hours,minutes,sec)
else:
return '{0} days, {1} hours, {2} minutes and {3} seconds.'.format(days,hours,minutes,sec)
def ready(bot, config):
if config['modules']['general'] == True:
bot.add_cog(cogs.general.General(bot, config))
if config['modules']['fun'] == True:
bot.add_cog(cogs.fun.Fun(bot, config))
if config['modules']['mod'] == True:
bot.add_cog(cogs.mod.Mod(bot, config, thr))
if config['modules']['catfacts'] == True:
bot.add_cog(cogs.catfacts.Catfacts(bot, config))
if config['modules']['testing'] == True:
bot.add_cog(cogs.testing.Testing(bot, config))
ready(bot, config)
bot.run(config['token'])