| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- from discord.ext import commands
- import discord
- from discord import app_commands
- import time
- from typing import Optional
- #from query.channel import get_interact
- from query.user import ignore_user, unignore_user, is_ignored
- from common.logging import report
- #from local_settings import OUTPUT_CHANNEL
- from common.settings import check_ignore_interaction
- async def setup(bot: commands.Bot) -> None:
- await bot.add_cog(GeneralCommands(bot))
- class GeneralCommands(commands.Cog):
- """General functionality."""
- def __init__(self, bot: commands.Bot) -> None:
- self.bot = bot
- @app_commands.command(
- name="ping",
- description="Get the bot's current websocket and API latency.",
- )
- async def ping(self, interaction: discord.Interaction) -> None:
- start_time = time.time()
- # message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
- end_time = time.time()
- await interaction.response.send_message(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.", ephemeral=True)
- # @commands.command(
- # description="Send a message",
- # brief="Chat",
- # help="Make a chat message",
- # aliases= ("say", "pm", "dm", "echo", "print")
- # )
- # async def msg(self, ctx: commands.Context, channel: Optional[discord.TextChannel], user: Optional[discord.User], *, message: str = None):
- # # Halt on ignore list.
- # if await check_ignore_interaction(self.bot.pg, interaction):
- # return
- #
- # #print(ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages)
- # if not message:
- # if channel:
- # await ctx.send(f"What would you like me to say in `{channel}`?")
- # elif user:
- # await ctx.send(f"What would you like me to say to `{user}`?")
- # else:
- # await ctx.send("What would you like me to say?")
- # elif channel:
- # if await get_interact(self.bot.pg, channel.id) or ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
- # await channel.send(message)
- # await report(self.bot, f"`{ctx.author}` @ {channel.mention}: {message}", ctx.guild)
- # else:
- # await ctx.send(f"Interactive mode for {channel} is deactivated.")
- # elif user and ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
- # await user.send(message)
- # await report(self.bot, f"`{ctx.author}` has sent {message} to `{user.name}`")
- # else:
- # await ctx.send(message)
- # await report(self.bot, f"`{ctx.author}` has sent {message} locally.", ctx.guild)
- @app_commands.command(
- name="ignoreme",
- description="Get ignored.",
- )
- async def ignoreme(self, interaction: discord.Interaction) -> None:
- # Halt on ignore list.
- if await check_ignore_interaction(self.bot.pg, interaction):
- return
- await ignore_user(self.bot.pg, interaction.user.id)
- await interaction.response.send_message(f"To revert this use the `/unignoreme` command.")
- await report(self.bot, " has requested to be ignored.", user=interaction.user)
- @app_commands.command(
- name="unignoreme",
- description="No longer get ingored.",
- )
- async def unignoreme(self, interaction: discord.Interaction) -> None:
- await unignore_user(self.bot.pg, interaction.user.id)
- await interaction.response.send_message(f"I shall now interact with you again where my channel settings allow it.")
- await report(self.bot, " has requested to be un-ignored.", user=interaction.user)
- @app_commands.command(
- name="isignored",
- description="Ignore status for user.",
- )
- async def isignored(self, interaction: discord.Interaction, user: Optional[discord.User]) -> None:
- # Halt on ignore list.
- if await check_ignore_interaction(self.bot.pg, interaction.user):
- return
- if not user:
- user = interaction.user
- if await is_ignored(self.bot.pg, user.id):
- await interaction.response.send_message(f"I am ignoring `{user}`.")
- else:
- await interaction.response.send_message(f"I am not ignoring `{user}`.")
|