Browse Source

уже почти релиз

huy
gsd 2 years ago
parent
commit
92186a4770
  1. 11
      admin_ext/kick.py
  2. 13
      admin_ext/unban.py
  3. 75
      other_ext/url_checker.py
  4. 64
      other_ext/webhook_helper.py
  5. 2
      user_ext/profile.py

11
admin_ext/kick.py

@ -1,7 +1,9 @@
import discord
class Extension:
core = None
def __init__(self, core):
self.core = core
@core.tree.command(name = "kick", description = "Кикнуть игрока")
@discord.app_commands.describe(profile=core.ANY_INPUT, reason="причина")
async def kick_player(
@ -10,6 +12,9 @@ class Extension:
reason: str = ""
):
await interaction.response.defer(thinking=True)
steam64 = await core.GetSteam64OfDiscord(interaction.user)
player = await core.GetPlayer(profile, steam64, False)
return await interaction.followup.send(f'{await player.kick(reason)}', ephemeral=False)
return await interaction.followup.send(f'{await self.__call__(profile, reason, interaction.user)}', ephemeral=False)
async def __call__(self, profile, reason, requester):
steam64 = await self.core.GetSteam64OfDiscord(requester)
player = await self.core.GetPlayer(profile, steam64, False)
return await player.kick(reason)

13
admin_ext/unban.py

@ -1,14 +1,19 @@
import discord
class Extension:
core = None
def __init__(self, core):
self.core = core
@core.tree.command(name = "unban", description = "Разбанить игрока")
@discord.app_commands.describe(profile=core.ANY_INPUT)
async def ban_player(
async def unban_player(
interaction: discord.Interaction,
profile: str
):
await interaction.response.defer(thinking=True)
steam64 = await core.GetSteam64OfDiscord(interaction.user)
player = await core.GetPlayer(profile, steam64, False)
return await interaction.followup.send(f'{await player.unban()}', ephemeral=False)
return await interaction.followup.send(f'{await self.__call__(profile, interaction.user)}', ephemeral=False)
async def __call__(self, profile, requester):
steam64 = await self.core.GetSteam64OfDiscord(requester)
player = await self.core.GetPlayer(profile, steam64, False)
return await player.unban()

75
other_ext/url_checker.py

@ -7,45 +7,54 @@ class Extension:
allow_domains = ["steamcommunity.com","s.team","tenor.com","tf2.pblr-nyk.pro", "pblr-nyk.pro", "youtu.be", "youtube.com"]
WEB_URL_REGEX = r"""(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)\b/?(?!@)))"""
allow_roles = [744928190895489074, 976924951447736453]
core = None
def __init__(self, core: DiscordClient):
self.core = core
@core.event
async def on_message(message: discord.Message):
if not message.guild:
return
await self.__call__(message)
if message.guild.id != core.main_server_id:
return
@core.event
async def on_message_edit(before: discord.Message, after: discord.Message):
await self.__call__(after)
if message.author == core.user:
async def __call__(self, message:discord.Message):
if not message.guild:
return
if not message.content:
return
if message.guild.id != self.core.main_server_id:
return
for maybe_url in reversed(re.findall(self.WEB_URL_REGEX, message.content)):
for rid in self.allow_roles:
if message.author.get_role(rid):
return
sub_continue = False
for domain in self.allow_domains:
if domain in maybe_url[:26]:
sub_continue = True
break
if sub_continue:
continue
print(f"Found url from {message.author} with url {maybe_url}")
try:
await message.reply(f"{message.author.mention} ссылки кидать нельзя!\nhttps://tf2.pblr-nyk.pro/fekalis/nigger_maslo.gif", delete_after = 60)
except Exception as err:
print(f"Cannot send message about delete url, error: {err}")
try:
await message.delete()
except Exception as err:
print(f"Cannot delete message with url, error: {err}")
return
if message.author == self.core.user:
return
if not message.content:
return
for maybe_url in reversed(re.findall(self.WEB_URL_REGEX, message.content)):
for rid in self.allow_roles:
if message.author.get_role(rid):
return
sub_continue = False
for domain in self.allow_domains:
if domain in maybe_url[:26]:
sub_continue = True
break
if sub_continue:
continue
print(f"Found url from {message.author} with url {maybe_url}")
try:
await message.reply(f"{message.author.mention} ссылки кидать нельзя!\nhttps://tf2.pblr-nyk.pro/fekalis/nigger_maslo.gif", delete_after = 60)
except Exception as err:
print(f"Cannot send message about delete url, error: {err}")
try:
await message.delete()
except Exception as err:
print(f"Cannot delete message with url, error: {err}")
return
return
return

64
other_ext/webhook_helper.py

@ -1,6 +1,8 @@
from discord.ext import tasks
import discord
from ..bot import DiscordClient
import asyncio
import traceback
class Extension:
core = None
@ -16,16 +18,16 @@ class Extension:
self.track_guild_id = core.main_server_id
self.webhook_reaction_translate = {
"😘":(self.core.loaded_extensions['ban'], {"profile":"", "reason":"", "minutes":0, "requester":""}),
"🔨":(self.core.loaded_extensions['ban'], {"profile":"", "reason":"", "minutes":30, "requester":""}),
"⚒️":(self.core.loaded_extensions['ban'], {"profile":"", "reason":"", "minutes":120, "requester":""}),
"😘":('ban', {"profile":"", "reason":"", "minutes":0, "requester":""}),
"🔨":('ban', {"profile":"", "reason":"", "minutes":30, "requester":""}),
"⚒️":('ban', {"profile":"", "reason":"", "minutes":120, "requester":""}),
"📨":(self.no_reason, {"requester":""}),
"🦵":"kick {reported_steam}",
"🔇":"mute {reported_steam}",
"😇":"unban {reported_steam}",
"hueglot:713139400028061767":"kick {original_steam}",
"🔍":"{reported_steam}",
"🔎":"{original_steam}"
"🦵":("kick", {"profile":""}),
"🔇":("mute", {"profile":""}),
"😇":("unban", {"profile":""}),
"hueglot:713139400028061767":("kick", {"profile":"", "requester_profile":""}),
"🔍":("profile", {"profile":""}),
"🔎":("unban", {"profile":"", "requester_profile":""})
}
@core.event
@ -48,11 +50,55 @@ class Extension:
if reaction.me:
return
if not reaction.message.guild.get_member(user.id).get_role(self.track_role_id):
return
if str(reaction.emoji) in self.webhook_reaction_translate.keys():
executor, kwargs = self.webhook_reaction_translate[str(reaction.emoji)]
if "requester" in kwargs:
kwargs["requester"] = user.id
if "reason" in kwargs and not user.id in self.no_reason:
def check(message: discord.Message):
return message.author == user and message.channel == reaction.message.channel
try:
req_msg = await reaction.message.channel.send(content=f"{user.mention}!\nВведи причину отправив сообщение")
msg = await self.core.wait_for("message", timeout=60.0, check=check)
except asyncio.TimeoutError:
await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} отменено спустя время", delete_after=60)
return
try:
await req_msg.delete()
except Exception as err:
print("Cannot delete request reason message, error: " +err)
#не ну это пиздец
if msg.content.split(" ") > 0 and msg.content.lower().split(" ")[0] == "отмена":
return await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} отменено по твоей воле", delete_after=60)
else:
kwargs["reason"] = msg.content
if "reason" in kwargs and user.id in self.no_reason:
kwargs["reason"] = self.no_reason[user.id]
del self.no_reason[user.id]
if "profile" in kwargs:
kwargs["profile"] = reaction.message.embeds[0].url
if "requester_profile" in kwargs:
kwargs["profile"] = reaction.message.embeds[0].author.url
try:
if type(executor) == str:
result = await self.core.loaded_extensions[executor](**kwargs)
else:
result = await executor(**kwargs)
except Exception as err:
traceback.print_exc()
return await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} невозможно из-за ошибки: {err}. Стоит написать добродею!", delete_after=60)
return await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} дало ответ: {result}")
async def null_reason(self, requester):
self.no_reason[requester] = "no reason"
return "Следующий бан будет без причины"

2
user_ext/profile.py

@ -13,7 +13,7 @@ class Extension:
profile: str = ""
):
await interaction.response.defer(thinking=True)
player = self.__call__(profile, interaction.user)
player = await self.__call__(profile, interaction.user)
return await interaction.followup.send(embed=player.embed, ephemeral=False)
async def __call__(self, profile:str, discord_user: discord.Member) -> Player:

Loading…
Cancel
Save