tickets_plus.cogs.main_utils
Miscellaneous commands that don't fit anywhere else.
They are various commands that don't fit into any other category. They are in free discord commands not assigned to groups. If the command set warrants it, we may move it to a group.
Typical usage example:
from tickets_plus import bot bot_instance = bot.TicketsPlusBot(...) await bot_instance.load_extension("tickets_plus.cogs.main_utils")
1"""Miscellaneous commands that don't fit anywhere else. 2 3They are various commands that don't fit into any other category. 4They are in free discord commands not assigned to groups. 5If the command set warrants it, we may move it to a group. 6 7Typical usage example: 8 ```py 9 from tickets_plus import bot 10 bot_instance = bot.TicketsPlusBot(...) 11 await bot_instance.load_extension("tickets_plus.cogs.main_utils") 12 ``` 13""" 14# License: EPL-2.0 15# SPDX-License-Identifier: EPL-2.0 16# Copyright (c) 2021-present The Tickets+ Contributors 17# This Source Code may also be made available under the following 18# Secondary Licenses when the conditions for such availability set forth 19# in the Eclipse Public License, v. 2.0 are satisfied: GPL-3.0-only OR 20# If later approved by the Initial Contributor, GPL-3.0-or-later. 21 22import logging 23 24import discord 25from discord import app_commands, utils 26from discord.ext import commands 27 28from tickets_plus import bot 29from tickets_plus.database import const 30 31 32class FreeCommands(commands.Cog, name="General Random Commands"): 33 """General commands that don't fit anywhere else. 34 35 We assign various commands that don't fit anywhere else to this cog. 36 They are in free discord commands not assigned to groups. 37 If a context is big enough, we may move it to a group. 38 """ 39 40 def __init__(self, bot_instance: bot.TicketsPlusBot): 41 """Initialize the FreeCommands cog. 42 43 We initialize some attributes here for later use. 44 45 Args: 46 bot_instance: The bot instance that loaded this cog. 47 """ 48 self._bt = bot_instance 49 logging.info("Loaded %s", self.__class__.__name__) 50 51 @app_commands.command(name="ping", description="The classic ping command. Checks the bot's latency.") 52 async def ping(self, ctx: discord.Interaction) -> None: 53 """The classic ping command. Checks the bot's latency. 54 55 This command is used to check the bot's latency. 56 It responds with the bot's latency in milliseconds. 57 58 Args: 59 ctx: The interaction context. 60 """ 61 embd = discord.Embed(title="Pong!", 62 description=f"The bot is online.\nPing: " 63 f"{str(round(self._bt.latency * 1000))}ms", 64 color=discord.Color.green()) 65 await ctx.response.send_message(embed=embd) 66 67 @app_commands.command(name="version", description="Get the bot's version.") 68 async def version(self, ctx: discord.Interaction) -> None: 69 """This command is used to check the bot's version. 70 71 Responds with the bot's version and a link to the source code. 72 73 Args: 74 ctx: The interaction context. 75 """ 76 emd = discord.Embed( 77 title="Tickets+", 78 description=f"Bot version: {const.VERSION}\n" 79 "This bot is open source and experimental!", 80 color=discord.Color.from_str("0x00FFFF"), 81 ).add_field( 82 name="Source Code:", 83 value=("[Available on GitHub](https://github.com/Tech-TTGames/Tickets-Plus)" 84 "\nThis is the place to report bugs and suggest features."), 85 ) 86 # .add_field(name="Get Support:", 87 # value="[Join the support server](<NO SUPPORT SERVER YET>)") 88 await ctx.response.send_message(embed=emd) 89 90 @app_commands.command(name="invite", description="Invite the bot to a server.") 91 async def invite(self, ctx: discord.Interaction) -> None: 92 """Invite the bot to a server. 93 94 This command is used to invite the bot to a server. 95 It responds with a link to invite the bot to a server. 96 97 Args: 98 ctx: The interaction context. 99 """ 100 app = await ctx.client.application_info() 101 admn_perms = discord.Permissions(535059492056) 102 safe_perms = discord.Permissions(535059492048) 103 if app.bot_public: 104 emd = discord.Embed(title="Tickets+", 105 description="Invite the bot to your server with this links:\n", 106 color=discord.Color.from_str("0x00FFFF")) 107 emd.add_field( 108 name="Admin Permissions:", 109 value=f"[Click Here!]({utils.oauth_url(app.id, permissions=admn_perms)})", 110 ) 111 emd.add_field( 112 name="Safe Permissions:", 113 value=f"[Click Here!]({utils.oauth_url(app.id, permissions=safe_perms)})", 114 ) 115 else: 116 flg = False 117 if app.team: 118 # Split to avoid errors ie AttributeError 119 if ctx.user in app.team.members: 120 flg = True 121 if ctx.user == app.owner: 122 flg = True 123 if flg: 124 emd = discord.Embed(title="Tickets+", 125 description="Welcome back authorised user!\n" 126 "Invite the bot to your server with this link:\n", 127 color=discord.Color.from_str("0x00FFFF")) 128 emd.add_field( 129 name="Invite Link:", 130 value=f"[Click Here!]({utils.oauth_url(app.id, permissions=admn_perms)})", 131 ) 132 else: 133 emd = discord.Embed(title="Tickets+", 134 description="Sorry! This instance of the bot is not public." 135 " You can't invite it to your server.", 136 color=discord.Color.red()) 137 await ctx.response.send_message(embed=emd) 138 139 140async def setup(bot_instance: bot.TicketsPlusBot) -> None: 141 """Sets up the free commands. 142 143 Called by the bot when the cog is loaded. 144 It adds the cog to the bot. 145 146 Args: 147 bot_instance: The bot instance. 148 """ 149 await bot_instance.add_cog(FreeCommands(bot_instance))
class
FreeCommands(discord.ext.commands.cog.Cog):
33class FreeCommands(commands.Cog, name="General Random Commands"): 34 """General commands that don't fit anywhere else. 35 36 We assign various commands that don't fit anywhere else to this cog. 37 They are in free discord commands not assigned to groups. 38 If a context is big enough, we may move it to a group. 39 """ 40 41 def __init__(self, bot_instance: bot.TicketsPlusBot): 42 """Initialize the FreeCommands cog. 43 44 We initialize some attributes here for later use. 45 46 Args: 47 bot_instance: The bot instance that loaded this cog. 48 """ 49 self._bt = bot_instance 50 logging.info("Loaded %s", self.__class__.__name__) 51 52 @app_commands.command(name="ping", description="The classic ping command. Checks the bot's latency.") 53 async def ping(self, ctx: discord.Interaction) -> None: 54 """The classic ping command. Checks the bot's latency. 55 56 This command is used to check the bot's latency. 57 It responds with the bot's latency in milliseconds. 58 59 Args: 60 ctx: The interaction context. 61 """ 62 embd = discord.Embed(title="Pong!", 63 description=f"The bot is online.\nPing: " 64 f"{str(round(self._bt.latency * 1000))}ms", 65 color=discord.Color.green()) 66 await ctx.response.send_message(embed=embd) 67 68 @app_commands.command(name="version", description="Get the bot's version.") 69 async def version(self, ctx: discord.Interaction) -> None: 70 """This command is used to check the bot's version. 71 72 Responds with the bot's version and a link to the source code. 73 74 Args: 75 ctx: The interaction context. 76 """ 77 emd = discord.Embed( 78 title="Tickets+", 79 description=f"Bot version: {const.VERSION}\n" 80 "This bot is open source and experimental!", 81 color=discord.Color.from_str("0x00FFFF"), 82 ).add_field( 83 name="Source Code:", 84 value=("[Available on GitHub](https://github.com/Tech-TTGames/Tickets-Plus)" 85 "\nThis is the place to report bugs and suggest features."), 86 ) 87 # .add_field(name="Get Support:", 88 # value="[Join the support server](<NO SUPPORT SERVER YET>)") 89 await ctx.response.send_message(embed=emd) 90 91 @app_commands.command(name="invite", description="Invite the bot to a server.") 92 async def invite(self, ctx: discord.Interaction) -> None: 93 """Invite the bot to a server. 94 95 This command is used to invite the bot to a server. 96 It responds with a link to invite the bot to a server. 97 98 Args: 99 ctx: The interaction context. 100 """ 101 app = await ctx.client.application_info() 102 admn_perms = discord.Permissions(535059492056) 103 safe_perms = discord.Permissions(535059492048) 104 if app.bot_public: 105 emd = discord.Embed(title="Tickets+", 106 description="Invite the bot to your server with this links:\n", 107 color=discord.Color.from_str("0x00FFFF")) 108 emd.add_field( 109 name="Admin Permissions:", 110 value=f"[Click Here!]({utils.oauth_url(app.id, permissions=admn_perms)})", 111 ) 112 emd.add_field( 113 name="Safe Permissions:", 114 value=f"[Click Here!]({utils.oauth_url(app.id, permissions=safe_perms)})", 115 ) 116 else: 117 flg = False 118 if app.team: 119 # Split to avoid errors ie AttributeError 120 if ctx.user in app.team.members: 121 flg = True 122 if ctx.user == app.owner: 123 flg = True 124 if flg: 125 emd = discord.Embed(title="Tickets+", 126 description="Welcome back authorised user!\n" 127 "Invite the bot to your server with this link:\n", 128 color=discord.Color.from_str("0x00FFFF")) 129 emd.add_field( 130 name="Invite Link:", 131 value=f"[Click Here!]({utils.oauth_url(app.id, permissions=admn_perms)})", 132 ) 133 else: 134 emd = discord.Embed(title="Tickets+", 135 description="Sorry! This instance of the bot is not public." 136 " You can't invite it to your server.", 137 color=discord.Color.red()) 138 await ctx.response.send_message(embed=emd)
General commands that don't fit anywhere else.
We assign various commands that don't fit anywhere else to this cog. They are in free discord commands not assigned to groups. If a context is big enough, we may move it to a group.
FreeCommands(bot_instance: tickets_plus.bot.TicketsPlusBot)
41 def __init__(self, bot_instance: bot.TicketsPlusBot): 42 """Initialize the FreeCommands cog. 43 44 We initialize some attributes here for later use. 45 46 Args: 47 bot_instance: The bot instance that loaded this cog. 48 """ 49 self._bt = bot_instance 50 logging.info("Loaded %s", self.__class__.__name__)
Initialize the FreeCommands cog.
We initialize some attributes here for later use.
Arguments:
- bot_instance: The bot instance that loaded this cog.
141async def setup(bot_instance: bot.TicketsPlusBot) -> None: 142 """Sets up the free commands. 143 144 Called by the bot when the cog is loaded. 145 It adds the cog to the bot. 146 147 Args: 148 bot_instance: The bot instance. 149 """ 150 await bot_instance.add_cog(FreeCommands(bot_instance))
Sets up the free commands.
Called by the bot when the cog is loaded. It adds the cog to the bot.
Arguments:
- bot_instance: The bot instance.