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