Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
backup + basic + localization fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Weever1337 committed Oct 31, 2023
1 parent 8b07c31 commit 806890f
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 39 deletions.
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from src import bot
from os import getenv


bot.Bot().run(getenv("DISCORD_TOKEN", "token"))
8 changes: 5 additions & 3 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import disnake
from disnake.ext import commands
from datetime import datetime

# from disnake.ext.ipc import Server

Expand All @@ -13,6 +14,7 @@
from .utils.misc import get_prefix, is_command_disabled



class Bot(commands.Bot):
"""The base class of Synth bot."""

Expand Down Expand Up @@ -105,8 +107,8 @@ async def on_ready(self) -> None:
await self.wait_until_ready()
await self.change_presence(
activity=disnake.Activity(
type=disnake.ActivityType.streaming,
name="New multi-functional bot, Synth",
state="Release soon...",
type=disnake.ActivityType.watching,
name=f"{len(self.guilds)} | >>help",
state="Release soon..."
)
)
194 changes: 193 additions & 1 deletion src/cogs/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from typing import Union
from src.utils.misc import check_if_user_is_developer
from disnake import Localized
import datetime
from memory_profiler import memory_usage

startup = datetime.datetime.now()

class BasicUtility(commands.Cog):
"""Basic utility commands."""
Expand All @@ -28,7 +31,7 @@ def __init__(self, bot):
65536: "<:developer:1168622649967116378>",
131072: "<:developer:1168622649967116378>",
262144: "<:shield:1168250173089140956>",
1048576: "⚠️",
1048576: "<:error:1168968103984636014>",
133172312: "<:synth_dev:1168623393717899314>",
}

Expand Down Expand Up @@ -150,6 +153,195 @@ async def server(self, interaction: disnake.MessageCommandInteraction):
embed.set_image(url=interaction.guild.banner)
await interaction.send(embed=embed)

@commands.slash_command(
name="clear",
description="Clear messages from chat"
)
async def clear(
self, interaction: disnake.MessageCommandInteraction,
amount: int,
channel: disnake.TextChannel = commands.Param(
name="channel",
description="The channel to clear messages from",
default=None,
)
):
if channel is None:
channel = interaction.channel

if amount > 100:
await interaction.send(embed=disnake.Embed(
title="Sorry, the maximum amount of messages to delete is 100",
color=disnake.Color.red()).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar),
delete_after=10)
return
try:
deleted = await channel.purge(limit=amount)
except disnake.Forbidden:
await interaction.send(embed=disnake.Embed(
title="Sorry, the bot doesn't have enough permissions to delete messages",
color=disnake.Color.red()).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar),
delete_after=10)
return
except disnake.HTTPException:
await interaction.send(embed=disnake.Embed(
title="Sorry, the bot doesn't have enough permissions to delete messages",
color=disnake.Color.red()).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar),
delete_after=10)
return

embed = disnake.Embed(color=0x2F3136)
embed.title = "<a:loading:1168599537682755584> Cleaning messages..."
embed.description = f"Deleted **{len(deleted)}** messages"
embed.set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar)
await interaction.channel.send(embed=embed, delete_after=10)

@commands.slash_command(
name="botinfo",
description="Display information about the bot."
)
async def botinfo(self, interaction: disnake.MessageCommandInteraction):
ch = []
for guild in self.bot.guilds:
for channel in guild.channels:
ch.append(channel.name)
embed = disnake.Embed(
title="Information about Synth",
description="**Synth** - is a multi-functional Discord bot.",
color=0x2F3136
).set_thumbnail(url = self.bot.user.avatar)
embed.add_field(
name="Main",
value=f"<:ping:1168968111920255086> Ping: **{round(self.bot.latency * 1000)} ms\n**"
f"<:ram:1168969950275321927> RAM: **{round(memory_usage()[0], 2)} mb**\n"
f"<:uptime:1168968110154457088> Uptime: {format_dt(startup, style = 'F')}\n",
inline=False
)
embed.add_field(
name="Popularity",
value=f"<:gear:1168228790183415868> Servers: **{len(self.bot.guilds)}**\n"
f"<:moderator:1168622624629334136> Big servers (1000+): **{len([g for g in self.bot.guilds if g.member_count >= 1000])}**\n"
f"<:users:1168968100637589607> Users: **{len(set(self.bot.get_all_members()))}**\n"
f"<:channel:1168968099194744912> Channels: **{len(ch)}**\n",
inline=False
)
embed.add_field(
name="Other Information",
value=f"<:staff:1168622635228344403> Created at: **31/10/2023**\n"
f"<:information:1168237956591530065> Bot version: **v1.0.0.**\n"
f"<:python:1168970645980315658> Python version: **3.11.6**\n"
f"<:crown:1168970928970023042> Owners: [Snaky](https://discord.com/users/999682446675161148), "
f"[Weever](https://discord.com/users/419159175009009675), "
f"[LazyDev](https://discord.com/users/1167458549132181668)",
inline=False
)
embed.set_footer(text="Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar)
support = 'Support server'
website = 'Website'

support = disnake.ui.Button(label=support, url='https://discord.gg/7vT3H3tVYp')
website = disnake.ui.Button(label=website, url='https://synth.xyz/')

await interaction.send(embed=embed, components=[support, website])

@commands.slash_command(
name="add-roles",
description="Add a specific role to all users"
)
async def addroles(
self, interaction: disnake.MessageCommandInteraction,
role: disnake.Role = commands.Param(
name="role",
description="The role to add to all users",
required=True
)
):
total_members = len(interaction.guild.members)
failed_members = []

if not role.permissions.administrator:
msg = await interaction.send(embed=disnake.Embed(
title=f"<a:loading:1168599537682755584> Please wait...",
description=f"Adding {role.mention} to **{total_members}** members.\n"
f"Please do not delete this message, until the proccess is done.",
color=0x2F3136
).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar))

for member in interaction.guild.members:
try:
await member.add_roles(role)
except disnake.Forbidden:
failed_members.append(member)

if failed_members:
failed_count = len(failed_members)
await msg.edit(embed=disnake.Embed(
description=f"Successfully added role to **{total_members - failed_count}/{total_members}** members. "
f"Failed to add role to **{failed_count}** members.",
color=0x2F3136
).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar))
else:
await msg.edit(embed=disnake.Embed(
description=f"Successfully added role to all **{total_members}** members.",
color=0x2F3136
).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar))
else:
await interaction.send(embed=disnake.Embed(
description=f"<a:error:1168599839899144253> | Sorry, this role has administrator permissions,"
f"so I can't give it to all members",
color=0xFF0000
))

@commands.slash_command(
name="remove-roles",
description="Remove a specific role from all users"
)
async def removeroles(
self, interaction: disnake.MessageCommandInteraction,
role: disnake.Role = commands.Param(
name="role",
description="The role to remove from all users",
required=True
)
):
total_members = len(interaction.guild.members)
failed_members = []

if not role.permissions.administrator:
msg = await interaction.send(embed=disnake.Embed(
title=f"<a:loading:1168599537682755584> Please wait...",
description=f"Removing {role.mention} from **{total_members}** members.\n"
f"Please do not delete this message, until the proccess is done.",
color=0x2F3136
).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar))

for member in interaction.guild.members:
try:
await member.remove_roles(role)
except disnake.Forbidden:
failed_members.append(member)

if failed_members:
failed_count = len(failed_members)
await msg.edit(embed=disnake.Embed(
description=f"Successfully removed role from **{total_members - failed_count}/{total_members}** members. "
f"Failed to remove role from **{failed_count}** members.",
color=0x2F3136
).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar))
else:
await msg.edit(embed=disnake.Embed(
description=f"Successfully removed role from all **{total_members}** members.",
color=0x2F3136
).set_footer(text=f"Synth © 2023 | All Rights Reserved", icon_url=self.bot.user.avatar))
else:
await interaction.send(embed=disnake.Embed(
description=f"<a:error:1168599839899144253> | Sorry, this role has administrator permissions,"
f"so I can't remove it from all members",
color=0xFF0000
))




def setup(bot: commands.Bot):
bot.add_cog(BasicUtility(bot=bot))
23 changes: 12 additions & 11 deletions src/utils/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,18 @@ def extract_attributes_from_class(


def convert_guild_channel_to_json(guild_channel: disnake.abc.GuildChannel) -> Dict:
return extract_attributes_from_class(
attributes=CHANNEL_ATTRIBUTE_NAMES,
_class=guild_channel,
convert={
"type": lambda type_value: type_value[1],
"overwrites": lambda overwrites: convert_permission_overwrite_to_list(
overwrites
),
"video_quality_mode": lambda video_quality_mode: video_quality_mode[1],
},
)
if guild_channel.type != disnake.ChannelType.category:
return extract_attributes_from_class(
attributes=CHANNEL_ATTRIBUTE_NAMES,
_class=guild_channel,
convert={
"type": lambda type_value: type_value[1],
"overwrites": lambda overwrites: convert_permission_overwrite_to_list(
overwrites
),
"video_quality_mode": lambda video_quality_mode: video_quality_mode[1],
},
)


async def convert_guild_role_to_json(guild_role: disnake.Role) -> Dict:
Expand Down
2 changes: 1 addition & 1 deletion src/utils/locale/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"GIVEAWAY_CREATE_COMMAND_DURATION_DESC": "For example: 1d1h1m1s (1 day, 1 hour, 1 minute, 1 second)",
"GIVEAWAY_REROLL_COMMAND_NAME": "reroll",
"GIVEAWAY_REROLL_COMMAND_DESC": "Re-roll the giveaway",
"GIVEAWAY_REROLL_COMMAND_MESSAGEID_NAME": "message id",
"GIVEAWAY_REROLL_COMMAND_MESSAGEID_NAME": "message-id",
"GIVEAWAY_REROLL_COMMAND_MESSAGEID_DESC": "Message ID to giveaway",
"GIVEAWAY_REROLL_COMMAND_WINNERS_NAME": "winners",
"GIVEAWAY_REROLL_COMMAND_WINNERS_DESC": "Pick the number of winners",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/locale/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"GIVEAWAY_REROLL_COMMAND_WINNERS_DESC": "Выберите число победителей",


"INVITE_TRACKER_COMMAND_NAME": "трекер_приглашений",
"INVITE_TRACKER_COMMAND_NAME": "инвайт-трекер",
"INVITE_TRACKER_COMMAND_DESC": "Установка трекера приглашений",
"INVITE_TRACKER_SET_CHANNEL_NAME": "канал",
"INVITE_TRACKER_SET_CHANNEL_DESC": "Выберите канал",
Expand Down
10 changes: 5 additions & 5 deletions src/utils/locale/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


"PAY_COMMAND_NAME": "переказ",
"PAY_COMMAND_DESC": "Зробити переказ грошей іншому користувачеві",
"PAY_COMMAND_DESC": "Make a money transfer to another user",


"FORMS_COMMAND_NAME": "форми",
Expand All @@ -27,7 +27,7 @@
"FORMS_DELETE_COMMAND_FORM_NAME": "форма",
"FORMS_DELETE_COMMAND_FORM_DESC": "Оберіть форму форму",

"ROLL_COMMAND_NAME": "гральні кості",
"ROLL_COMMAND_NAME": "гральні-кості",
"ROLL_COMMAND_DESC": "Зробити кидок кубика",
"ROLL_COMMAND_NUMBER": "Зазвичай: 6",
"ROLL_COMMAND_NUMBER_NAME": "кількість",
Expand Down Expand Up @@ -56,19 +56,19 @@
"GIVEAWAY_CREATE_COMMAND_DESC": "Створити розіграш",
"GIVEAWAY_CREATE_COMMAND_PRIZE_NAME": "приз",
"GIVEAWAY_CREATE_COMMAND_PRIZE_DESC": "Оберіть приз",
"GIVEAWAY_CREATE_COMMAND_WINNERS_NAME": "переможець/переможців",
"GIVEAWAY_CREATE_COMMAND_WINNERS_NAME": "переможців",
"GIVEAWAY_CREATE_COMMAND_WINNERS_DESC": "Напишіть, скільки переможців буде в розіграші",
"GIVEAWAY_CREATE_COMMAND_DURATION_NAME": "тривалість",
"GIVEAWAY_CREATE_COMMAND_DURATION_DESC": "Наприклад, 1d1h1m1s (1 день, 1 година, 1 хвилина, 1 секунда)",
"GIVEAWAY_REROLL_COMMAND_NAME": "реролл",
"GIVEAWAY_REROLL_COMMAND_DESC": "Переобрати переможця(-ів) в розіграші",
"GIVEAWAY_REROLL_COMMAND_MESSAGEID_NAME": "айді_повідомлення",
"GIVEAWAY_REROLL_COMMAND_MESSAGEID_DESC": "ID повідомлення розіграша",
"GIVEAWAY_REROLL_COMMAND_WINNERS_NAME": "переможець/переможців",
"GIVEAWAY_REROLL_COMMAND_WINNERS_NAME": "переможців",
"GIVEAWAY_REROLL_COMMAND_WINNERS_DESC": "Напишіть, скільки переможців буде в розіграші",


"INVITE_TRACKER_COMMAND_NAME": "інвайт_трекер",
"INVITE_TRACKER_COMMAND_NAME": "інвайт-трекер",
"INVITE_TRACKER_COMMAND_DESC": "Встановлення інвайт-трекера",
"INVITE_TRACKER_SET_CHANNEL_NAME": "канал",
"INVITE_TRACKER_SET_CHANNEL_DESC": "Оберіть канал, де буде інформація про запрошення різних користувачів",
Expand Down
18 changes: 1 addition & 17 deletions src/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Forbidden,
)
from disnake.ext import commands
import disnake

from . import main_db

Expand Down Expand Up @@ -87,20 +88,3 @@ async def predicate(ctx: commands.Context) -> bool:

return commands.check(predicate)


def has_bot_permissions():
async def predicate(ctx: commands.Context) -> bool:
bot_member = ctx.guild.get_member(ctx.bot.user.id)
if not bot_member.guild_permissions.administrator:
await ctx.send(
embed=Embed(
title="<<a:error:1168599839899144253> Error",
description="Bot hasn't got enough permissions to do this.",
colour=0xFF0000,
)
)
return False

return True

return commands.check(predicate)

0 comments on commit 806890f

Please sign in to comment.