ddos protection
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from threading import Lock
|
||||
|
||||
import discord
|
||||
import nltk
|
||||
@@ -15,6 +16,8 @@ LIL_STINKY_ID = 704043422276780072
|
||||
|
||||
|
||||
class RoboPage(discord.Client):
|
||||
db_path: str = 'messages.db'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RoboPage, self).__init__(*args, **kwargs)
|
||||
self.jokes = [
|
||||
@@ -23,7 +26,7 @@ class RoboPage(discord.Client):
|
||||
AssJoke(),
|
||||
DominosJoke()
|
||||
]
|
||||
self.db_path = 'messages.db'
|
||||
self.lock = Lock()
|
||||
|
||||
def run(self):
|
||||
return super().run(os.getenv('DISCORD_TOKEN'))
|
||||
@@ -52,8 +55,12 @@ class RoboPage(discord.Client):
|
||||
await message.reply(await self.get_cancelled_totals(limit=1000, days=14))
|
||||
|
||||
elif (m := re.search('top cancelled (?P<name>\w+)', message.content)) is not None:
|
||||
if self.lock.acquire(blocking=False):
|
||||
msg: discord.Message = await message.reply('Hold please...')
|
||||
await message.reply(await self.top_cancellations(user=m.group('name'), limit=1000, days=14))
|
||||
self.lock.release()
|
||||
else:
|
||||
await message.reply("I'm busy!")
|
||||
|
||||
for joke in self.jokes:
|
||||
if (scan_res := joke.scan(message)):
|
||||
|
||||
Reference in New Issue
Block a user