repl.it
@minx28/

MathsBot

Python

No description

fork
loading
Files
  • main.py
  • commands
  • commands.egg-info
  • utilities
  • calc_cooldown
  • client.py
  • helplist.py
  • latex-cheatsheet.pdf
  • leveling.py
  • mutes
  • other_events.py
  • permissions.py
  • pyproject.tmp
  • server.py
  • setup.py
  • stuff.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# JOIN THE MATHS DISCORD SERVER!!!
# http://bit.ly/discordmaths

import requests
import sys
import os
class Terminal:
  def __init__(self):
    sys.stdout=sys.stderr=self
    print("_ _\n\n\n**RESTART**\n\n\n_ _")
  def write(self,text):
    if not any(["GET" in text,"HEAD" in text]):
      requests.post(os.getenv("terminal"),json={"content":text})
  def flush(self):
    pass

#Terminal()

import discord
from client import *
import asyncio
import random
from datetime import datetime,timedelta
import shelve
from string import ascii_letters as letters,digits
from utilities.bright_colour import bright_colour as bc
import urllib

from other_events import message_delete,message_edit,member_join,member_leave,reaction_add

db=os.getenv("db")

skipping_number=False

chat_filter=lambda message:requests.get(f"https://swear-filter-api.minx28.repl.co/filter/{message.content}").text=="True"

swearword_list=lambda message:requests.get(f"https://swear-filter-api.minx28.repl.co/word-list/{message.content}").text

async def check_mutes(): # Function which auto-umutes people if the required time has elapsed
  while False:
    db_muted=requests.get(f"{db}/mutes").json()["result"]
    for user,time in db_muted.items():
      if datetime.now().timestamp()>time: # Check if time is up
        try:
          mention=await user_mentions_channel.send(discord.User(id=user).mention)
          member=mention.mentions[0]
          await member.remove_roles(muted)
          embed=discord.Embed(color=0x00ff00,title="User Unmute",timestamp=datetime.now())
          embed.add_field(name="User",value="{} (`{}`)".format(member.mention,member),inline=False)
          embed.add_field(name="Moderator",value="MathsBot",inline=False)
          await mod_log_channel.send(member.mention,embed=embed)
        except:
          pass
        requests.post(f"{db}/mutes/{user.id}",json=None)
        try:
          await member.send("**You have been unmuted!**")
        except:
          pass
    await asyncio.sleep(5)

async def cn():
  await notifs.edit(name="Notifications",colour=bc())

async def cnh():
  while True:
    now=datetime.now()
    if now.minute==now.second==0:
      await cn()
    await asyncio.sleep(1)

class Minx:
  def __init__(self):
    self.mind="ok"
  
minx=Minx()

async def process_message(message):

  import commands
  from stuff import prefix,roles,server,warnings_channel,log_channel,mod_log_channel,user_mentions_channel,level_up_channel,count_to_1000,bot_owner,muted,newbie,notifs
  from permissions import permissions,has_permission

  global skipping_number

  if not isinstance(message.channel,discord.abc.PrivateChannel):
    filtered=False #chat_filter(message)
    if not filtered:

      '''if message.content.count("$")>1:
        img="https://latex.codecogs.com/png.latex?%5Cbg_36393f%20%5Cdpi%7B300%7D%20%5CLARGE%20%5Cmathrm%7B%7B%5Ccolor%7Bwhite%7D{}%7D%7D".format(message.content.replace("$","").replace(" ","\%20"))
        urllib.request.urlretrieve(img, "tex.png")
        with open("tex.png", "rb") as picture:
          await message.channel.send(message.author.mention+":",file=discord.File(picture))'''

      if message.channel==count_to_1000 and message.author!=client.user:
        
        if message.author==bot_owner and message.content=="restore":
          skipping_number=True
          await message.delete()
          return
        if message.author==bot_owner and skipping_number:
          skipping_number=False
          return

        try:
          int(message.content)
        except ValueError:
          await message.delete()
          return
        prev=await message.channel.history(limit=2).flatten()
        prev=prev[1]
        if prev.author==client.user:
          prev.content="0"
        if prev.author==message.author:
          await count_to_1000.send("You can't count two consecutive numbers - back to the start!\n0")
          return
        if prev.author==client.user and message.content!="1":
          await count_to_1000.send(f"The next number should have been 1, not {message.content}! Back to the start!!\n0")
          return
        if int(message.content)!=int(prev.content)+1:
          await count_to_1000.send(f"The next number should have been {int(prev.content)+1}, not {message.content}! Back to the start!\n0")
          return

        topic_text="**Current Record: {}**.\nStuff about this channel (PLEASE READ):\nCount to 1000.\nYou can't skip numbers, and the same person can't post two or more consecutive numbers. If either of those are done, the count will be reset to 0.\nDon't ruin it for other people - if you intentionally and repeatedly make mistakes and mess around, you will be muted in this channel, temporarily or permanently, and the count can be restored anyway.\nIf we reach 1000, the target will be increased!"
        current_record=int(message.channel.topic[18:-454])
        if int(message.content)>current_record:
          topic_text=topic_text.format(message.content)
          await message.channel.edit(topic=topic_text)

      if message.content.startswith(prefix):
        command=message.content.strip(prefix).split()[0]
        if message.author==bot_owner:
          if command=="kill":
            exit()
          if command=="eval":
            await message.channel.send(eval(message.content.split(" ",1)[1]))
            return
          if command=="m":
            minx.mind=message.content[3:]
            return
        if command in permissions:
          params=message.content.strip(prefix).strip(command)[1:]

          if has_permission(message.author,command): # Permissions checker

            if command=="help":
              await commands.help(client,message)

            if command=="calc" or command=="calculate" or command=="c":
              await commands.calculate(client,message,params)

            if command=="ping":
              await commands.ping(client,message)

            if command=="bcc":
              await commands.bypass_calc_cooldown(client,message,message.mentions[0].id)
            
            if command=="purge":
              if int(params)>=10:
                await message.channel.send("Are you sure you want to purge {} messages? This will timeout in 10 seconds.".format(params))
                stuff=message.author,message.channel
                confirmation=await client.wait_for("message",timeout=10,check=(lambda m:(m.author,m.channel)==stuff))
                if confirmation.content.lower() not in ["yes","yeah","yep","ye","indeedly"]:
                  return
              await message.channel.purge(limit=int(params)+1)

            '''if command=="mute":
              await commands.mute(client,message,message.content.split()[2],message.content.split(" ",3)[3])'''

            if command=="unmute":
              await commands.unmute(client,message)

            if command=="warn":
              await commands.warn(client,message,message.mentions[0],message.content.split(" ",2)[2])

            if command=="kick":
              await commands.kick(client,message,message.mentions[0],message.content.split(" ",2)[2])

            if command=="ban":
              await commands.ban(client,message,message.mentions[0],message.content.split(" ",2)[2])

            if command=="unban":
              await commands.unban(client,message,message.content.split(" ",2)[1],message.content.split(" ",2)[2])

            if command=="rainbow":
              await commands.do_rainbow(client,message)

            if command in ["notifications","notifs","pings"]:
              await commands.notifs(client,message,message.author)

            if command=="announce":
              await commands.announce(client,message)

            if command=="cn":
              await commands.colour_notifs(client,message)

            if command=="fact":
              await commands.get_fact(client,message,message.content.split()[1])

            if command=="randomfact":
              await commands.get_fact(client,message,"random")

            if command=="latexhelp":
              await commands.latexhelp(client,message)

            if command=="translate":
              await commands.translate(client,message)

            if command=="ask":
              await commands.ask(client,message)

          else:
            await message.channel.send("You don't have permission to do this command!")
            
        else:
          await message.channel.send("Unknown command! Do `;help` for a list of commands which you have permission to use.")

      else: # All stuff which isn't commands
        if message.channel.id==521933352492597249:
          phrase="i accept the rules of the maths discord server"
          if len(message.content)<30 or message.content.count(":")>=2 or all([word not in message.content.lower() for word in phrase.split()]):
            await message.author.kick()
          if message.content.lower()==phrase:
            await message.author.remove_roles(newbie)
          await message.delete()

        if "qed" in message.content.lower():
          await message.add_reaction("\U0001F1F6")
          await message.add_reaction("\U0001F1EA")
          await message.add_reaction("\U0001F1E9")

        from string import printable
        if "poll:" in message.content.lower():
          for char in message.content:
            if char not in printable:
              try:
                await message.add_reaction(char)
              except:
                pass

        if "fortnite" in message.content.lower():
          try:
            await message.author.send("You have been kicked for use of the word `Fortnite`!\nhttps://discord.gg/JEWcqTn")
          except:
            pass
          await message.author.kick()

    else:
      embed=discord.Embed(title="User Warned for Bad Language",timestamp=datetime.now())
      embed.add_field(name="User",value="{} (`{}`)".format(message.author.mention,message.author),inline=False)
      embed.add_field(name="Message Content",value=message.content,inline=False)
      embed.add_field(name="Swearwords Detected",value=swearword_list(message).replace("<br>","\n"))
      embed.add_field(name="Message ID",value=message.id,inline=False)
      #embed.add_field(name="Warning ID (for removing warning)",value="".join([random.choice(letters+digits) for i in range(8)]))
      await warnings_channel.send(message.author.mention,embed=embed)
      await message.delete()
      try:
        await message.author.send("Please mind your language!")
      except:
        pass

@client.event
async def on_ready():
  print("Ready!")
  print(client.user)

  await client.change_presence(activity=discord.Game(";help | Go to https://bit.ly/mathsbot to contribute"))
  #asyncio.ensure_future(check_mutes())
  #asyncio.ensure_future(cnh())
  #loop=asyncio.get_event_loop()

@client.event
async def on_message(message):
  await process_message(message)
    
@client.event
async def on_message_delete(message): # Logs deleted messages
  await message_delete(client,message)

@client.event
async def on_message_edit(before,after): # Logs edited messages
  if after.author!=client.user:
    await message_edit(client,before,after)
  await process_message(after)

@client.event
async def on_member_join(member): # Posts join messages and mutes if necessary
  await member_join(client,member)

@client.event
async def on_member_remove(member): # Currently does nothing
  await member_leave(client,member)

@client.event
async def on_reaction_add(reaction,user):
  pass#await reaction_add(client,reaction,user)

import server
client.run(os.getenv("TOKEN"))
?