This commit is contained in:
2022-07-02 20:15:43 +03:00
committed by Slava
parent bab5d68a88
commit 04fadbab7a
5 changed files with 121 additions and 98 deletions

View File

@@ -1,8 +1,9 @@
import logging
import lib
from os import path, makedirs, rename, remove
from discord.ext import commands
from disnake.ext import commands
import lib
class Audio(commands.Cog):
@@ -34,7 +35,8 @@ class Audio(commands.Cog):
await at.save(f'tmp/{user.id}/{at.filename}')
guess = mimetypes.guess_type(f'tmp/{user.id}/{at.filename}')
if guess[0]:
await ctx.reply(f'it`s {guess}')
if guess[0].split('/')[0] == 'audio':
from pymediainfo import MediaInfo
file = f'tmp/{user.id}/{at.filename}'
duration = round(MediaInfo.parse(file).tracks[0].duration / 1000)
@@ -50,13 +52,13 @@ class Audio(commands.Cog):
lib.DB.add_audio(ctx.guild.id, user.id, audiolist)
rename(f'tmp/{user.id}/{at.filename}', f'audio/{user.id}/{at.filename}')
else:
await ctx.reply(f'Failed to find MIME type of {at.filename}', ephemeral=True)
elif guess[0].split('/')[0] != 'audio':
await ctx.reply(f'It not audio {at.filename}\n it`s {guess[0]}')
remove(f'tmp/{user.id}/{at.filename}')
else:
await ctx.reply("Has no Attachment", ephemeral=True)
await ctx.reply("Has no Attachment")
else:
await ctx.reply(f'You`re not admin. You can add audio only for your own account', ephemeral=True)
await ctx.reply(f'You`re not admin. You can add audio only for your own account')
def setup(bot): # an extension must have a setup function

View File

@@ -1,12 +1,10 @@
import logging
import dislash
import disnake
from disnake import Option, OptionType
from disnake.ext import commands
import lib
import discord
from discord.ext import commands
from dislash import Option, OptionType, slash_command
class General(commands.Cog):
@@ -36,29 +34,29 @@ class General(commands.Cog):
if bot_role and guest_role:
if member.bot == 0:
role = discord.utils.get(member.guild.roles, id=guest_role)
role = disnake.utils.get(member.guild.roles, id=guest_role)
else:
role = discord.utils.get(member.guild.roles, id=bot_role)
role = disnake.utils.get(member.guild.roles, id=bot_role)
logging.info(f"Adding to {member} role {role}")
await member.add_roles(role)
@commands.Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member):
async def on_member_update(self, before: disnake.Member, after: disnake.Member):
sql_update_query = f"""UPDATE "{after.guild.id}" set nick = ? where userid = ?"""
data_tuple = (after.nick, before.id)
lib.DB.work_with_db(sql_update_query, data_tuple)
@slash_command(
@commands.slash_command(
name="info",
description="Read list of tracks for user",
options=[
Option("user", "Specify any user", OptionType.USER),
Option("user", "Specify any user", OptionType.user),
]
)
async def info(self, ctx, user=None):
user = user or ctx.author
audio = lib.DB.read_db(ctx.guild.id, user.id)
rolelist = [r.mention for r in user.roles if r != ctx.guild.default_role]
async def info(self, inter, user=None):
user = user or inter.author
audio = lib.DB.read_db(inter.guild.id, user.id)
rolelist = [r.mention for r in user.roles if r != inter.guild.default_role]
if rolelist:
roles = "\n".join(rolelist)
else:
@@ -69,27 +67,26 @@ class General(commands.Cog):
else:
audios = "" + "\n".join(sorted(audio.split(", ")))
emb = discord.Embed(
emb = disnake.Embed(
title=f"General information",
description=f"General information on server about {user}",
icon=user.avatar_url
description=f"General information on server about {user}"
)
emb.set_thumbnail(url=user.avatar_url)
emb.set_thumbnail(url=user.avatar.url)
emb.add_field(name="General info",
value=f"Username: {user}\n"
f"Nickname: {user.nick}\n"
f"Joined at: {user.joined_at.strftime('%A, %B %d %Y @ %H:%M:%S')}", inline=False)
emb.add_field(name="Audio list", value=f"{audios}", inline=True)
emb.add_field(name="Roles list", value=f"{roles}", inline=True)
emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name))
emb.set_footer(text="Information requested by: {}".format(inter.author.display_name))
await ctx.reply(embed=emb, ephemeral=True)
await inter.response.send_message(embed=emb, ephemeral=True)
@slash_command(
@commands.slash_command(
name="set_guest_role",
description="Set Default bot role",
options=[
Option("role", "Specify role", OptionType.ROLE, required=True),
Option("role", "Specify role", OptionType.role, required=True),
]
)
@commands.has_permissions(administrator=True)
@@ -101,47 +98,62 @@ class General(commands.Cog):
@commands.has_permissions(administrator=True)
async def command_set_prefix(self, ctx, prefix: str):
await lib.Commands.set_prefix(ctx, prefix)
await ctx.reply(f"Prefix set to: `{prefix}`")
@slash_command(
@commands.slash_command(
name="set_prefix",
description="Setting up bot prefix",
options=[
Option("prefix", "Specify prefix", OptionType.STRING, required=True),
]
)
@dislash.has_permissions(administrator=True)
async def slash_set_prefix(self, ctx, prefix: str):
await lib.Commands.set_prefix(ctx, prefix)
@slash_set_prefix.error
@command_set_prefix.error
async def set_prefix_error(self, ctx, prefix):
await ctx.reply('You don`t have permissions', ephemeral=True)
@slash_command(
name="set_trigger_role",
description="Setting up role to trigger bot",
options=[
Option("role", "Specify role", OptionType.ROLE, required=True),
Option("prefix", "Specify prefix", OptionType.string, required=True),
]
)
@commands.has_permissions(administrator=True)
async def set_trigger_role(self, ctx, role):
await lib.Commands.write_json(ctx.guild.id, "tigger_role", role.id)
await ctx.send(f"Role to trigger set to : `{role.name}`", ephemeral=True)
async def slash_set_prefix(self, inter, prefix: str):
await lib.Commands.set_prefix(inter, prefix)
await inter.responce.send_message(f"Prefix set to: `{prefix}`", ephemeral=True)
@slash_command(
@slash_set_prefix.error
async def set_prefix_error(self, inter, prefix):
await inter.response.send_message('You don`t have permissions', ephemeral=True)
@commands.slash_command(
name="set_trigger_role",
description="Setting up role to trigger bot",
options=[
Option("role", "Specify role", OptionType.role, required=True),
]
)
@commands.has_permissions(administrator=True)
async def set_trigger_role(self, inter, role):
await lib.Commands.write_json(inter.guild.id, "tigger_role", role.id)
await inter.responce.send(f"Role to trigger set to : `{role.name}`", ephemeral=True)
@commands.slash_command(
name="set_bot_role",
description="Set Default bot role",
options=[
Option("role", "Specify role", OptionType.ROLE, required=True),
Option("role", "Specify role", OptionType.role, required=True),
]
)
@dislash.has_permissions(administrator=True)
@commands.has_permissions(administrator=True)
async def set_bot_role(self, ctx, role):
await lib.Commands.write_json(ctx.guild.id, "bot_role", role.id)
await ctx.send(f"Setted up bot role to: `{role.name}`", ephemeral=True)
@commands.slash_command()
async def help(self, inter):
embed = disnake.Embed(
title='Help', description='', colour=disnake.Colour.blue())
embed.set_footer(text='Have fun!')
embed.add_field(
name='Prefix',
value=
f'The current prefix for this server is {self.bot.command_prefix}',
inline=True)
await inter.response.send_message(embed=embed)
def setup(bot): # an extension must have a setup function
bot.add_cog(General(bot)) # adding a cog

View File

@@ -1,11 +1,10 @@
import logging
import discord
from discord.ext import commands
from dislash import slash_command
import disnake
from disnake.ext import commands
class Bot_info(commands.Cog):
class Bot_info(commands.Cog, name='Bot Info'):
def __init__(self, bot):
self.bot = bot # defining bot as global var in class
@@ -13,17 +12,21 @@ class Bot_info(commands.Cog):
async def on_ready(self):
logging.info(f'Cog {__name__.split(".")[1]} is ready!.')
@slash_command(name="info_bot") # this is for making a command
async def info_bot(self, ctx):
@commands.slash_command(name="info_bot") # this is for making a command
async def info_bot(self, inter):
# await ctx.send(f'Pong! {round(self.bot.latency * 1000)}')
emb = discord.Embed(
emb = disnake.Embed(
title=f"General information",
description=f"General information on about bot",
)
# emb.set_thumbnail(self.bot.avatar.url)
emb.add_field(name="Bot ping", value=f'Bot ping: {round(self.bot.latency * 1000)}', inline=True)
emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name))
emb.set_footer(text="Information requested by: {}".format(inter.author.display_name))
await inter.response.send_message(embed=emb, ephemeral=True)
await ctx.reply(embed=emb, ephemeral=True)
def setup(bot): # an extension must have a setup function