diff --git a/cogs.csv b/cogs.csv index db7a40e26..b726d96d0 100644 --- a/cogs.csv +++ b/cogs.csv @@ -4,13 +4,18 @@ Cocktail,Get information about different cocktails and their ingredients.,"Tools CogPaths,Get various paths for a cog.,"Tools, Informative",Kreusada Colour,View information about a colour.,"Tools, Informative",Kreusada ConsoleClearer,Completely clear your Red console,Tools,Kreusada +Counting,Counting channel.,Tools,"saurichable, Kreusada" EmbedCreator,"Create embeds using buttons, modals and dropdowns!",Tools,Kreusada Flags,Get the flag for a country,Tools,Kreusada +Gallery,Image only channels.,Tools,"saurichable, Kreusada" +Lock,Lock `@everyone` from sending messages.,Moderation,"saurichable, Kreusada" +Mentionable,Makes unmentionable roles mentionable.,Tools,"saurichable, Kreusada" MessageDeleter,"Delete messages from users and bots, inclusively or exclusively, in text channels.",Tools,Kreusada Minifier,Minify your code with python minifier,Tools,Kreusada MorseCode,Encode and decode morse code.,Tools,Kreusada NameGenerator,Generate names.,Tools,Kreusada OnThisDay,"Find out what happened today, in multiple different years in history.",Fun,Kreusada +Pick,Pick a random list,Tools,Kreusada PyPi,Get information about a package available on PyPi.,Tools,"Kreusada, OofChair" QR,Create QR codes.,Tools,Kreusada Quotes,Get a random quote,Fun,Kreusada diff --git a/counting/LICENSE.md b/counting/LICENSE.md new file mode 100644 index 000000000..fa0086a95 --- /dev/null +++ b/counting/LICENSE.md @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/counting/README.rst b/counting/README.rst new file mode 100644 index 000000000..a32369e92 --- /dev/null +++ b/counting/README.rst @@ -0,0 +1,96 @@ +.. _counting: + +======== +Counting +======== + +This is the cog guide for the 'Counting' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 1.4.0. Ensure + that you are up to date by running ``[p]cog update counting``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Make a counting channel with goals. + +-------- +Commands +-------- + +Here are all the commands included in this cog (9): + ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| Command | Help | ++==========================+=======================================================================================================+ +| ``[p]countset`` | Various Counting settings. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset channel`` | Set the counting channel. | +| | | +| | If channel isn't provided, it will delete the current channel. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset goal`` | Set the counting goal. | +| | | +| | If goal isn't provided, it will be deleted. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset reset`` | Reset the counter and start from 0 again! | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset role`` | Add a whitelisted role. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset settings`` | See current settings. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset start`` | Set the starting number. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset topic`` | Toggle counting channel's topic changing. | +| | | +| | If `on_off` is not provided, the state will be flipped.= | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset warnmsg`` | Toggle a warning message. | +| | | +| | If `on_off` is not provided, the state will be flipped. | +| | Optionally add how many seconds the bot should wait before deleting the message (0 for not deleting). | ++--------------------------+-------------------------------------------------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Counting. + +.. code-block:: ini + + [p]cog install kreusada-cogs counting + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load counting + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/counting/__init__.py b/counting/__init__.py new file mode 100644 index 000000000..42fb612df --- /dev/null +++ b/counting/__init__.py @@ -0,0 +1,10 @@ +from redbot.core.bot import Red +from redbot.core.utils import get_end_user_data_statement + +from .counting import Counting + +__red_end_user_data_statement__ = get_end_user_data_statement(__file__) + + +async def setup(bot: Red): + await bot.add_cog(Counting(bot)) diff --git a/counting/counting.py b/counting/counting.py new file mode 100644 index 000000000..455ab3b9c --- /dev/null +++ b/counting/counting.py @@ -0,0 +1,270 @@ +import asyncio +import datetime +import typing + +import discord +from discord.utils import find, get +from redbot.core import Config, checks, commands +from redbot.core.bot import Red + + +class Counting(commands.Cog): + """ + Make a counting channel with goals. + """ + + __version__ = "1.4.0" + + def __init__(self, bot: Red): + self.bot = bot + self.config = Config.get_conf(self, identifier=1564646215646, force_registration=True) + + self.config.register_guild( + channel=0, + previous=0, + goal=0, + last=0, + whitelist=None, + warning=False, + seconds=0, + topic=True, + ) + + async def red_delete_data_for_user(self, *, requester, user_id): + for guild in self.bot.guilds: + if user_id == await self.config.guild(guild).last(): + await self.config.guild(guild).last.clear() + + def format_help_for_context(self, ctx: commands.Context) -> str: + context = super().format_help_for_context(ctx) + return f"{context}\n\nVersion: {self.__version__}" + + @checks.admin() + @checks.bot_has_permissions(manage_channels=True, manage_messages=True) + @commands.group(autohelp=True, aliases=["counting"]) + @commands.guild_only() + async def countset(self, ctx: commands.Context): + """Various Counting settings.""" + + @countset.command(name="channel") + async def countset_channel( + self, ctx: commands.Context, channel: typing.Optional[discord.TextChannel] + ): + """Set the counting channel. + + If channel isn't provided, it will delete the current channel.""" + if not channel: + await self.config.guild(ctx.guild).channel.set(0) + return await ctx.send("Channel removed.") + await self.config.guild(ctx.guild).channel.set(channel.id) + goal = await self.config.guild(ctx.guild).goal() + if await self.config.guild(ctx.guild).topic(): + await self._set_topic(0, goal, 1, channel) + await ctx.send(f"{channel.name} has been set for counting.") + + @countset.command(name="goal") + async def countset_goal(self, ctx: commands.Context, goal: int = 0): + """Set the counting goal. + + If goal isn't provided, it will be deleted.""" + if not goal: + await self.config.guild(ctx.guild).goal.clear() + return await ctx.send("Goal removed.") + await self.config.guild(ctx.guild).goal.set(goal) + await ctx.send(f"Goal set to {goal}.") + + @countset.command(name="start") + async def countset_start(self, ctx: commands.Context, number: int): + """Set the starting number.""" + channel = ctx.guild.get_channel(await self.config.guild(ctx.guild).channel()) + if not channel: + return await ctx.send( + f"Set the channel with `{ctx.clean_prefix}countset channel `, please." + ) + await self.config.guild(ctx.guild).previous.set(number) + await self.config.guild(ctx.guild).last.clear() + goal = await self.config.guild(ctx.guild).goal() + next_number = number + 1 + if await self.config.guild(ctx.guild).topic(): + await self._set_topic(number, goal, next_number, channel) + await channel.send(number) + if c_id != ctx.channel.id: + await ctx.send(f"Counting start set to {number}.") + + @countset.command(name="reset") + async def countset_reset(self, ctx: commands.Context, confirmation: bool = False): + """Reset the counter and start from 0 again!""" + if not confirmation: + return await ctx.send( + "This will reset the ongoing counting. This action **cannot** be undone.\n" + f"If you're sure, type `{ctx.clean_prefix}countset reset yes`." + ) + p = await self.config.guild(ctx.guild).previous() + if p == 0: + return await ctx.send("The counting hasn't even started.") + c = ctx.guild.get_channel(await self.config.guild(ctx.guild).channel()) + if not c: + return await ctx.send( + f"Set the channel with `{ctx.clean_prefix}countchannel `, please." + ) + await self.config.guild(ctx.guild).previous.clear() + await self.config.guild(ctx.guild).last.clear() + await c.send("Counting has been reset.") + goal = await self.config.guild(ctx.guild).goal() + if await self.config.guild(ctx.guild).topic(): + await self._set_topic(0, goal, 1, c) + if c_id != ctx.channel.id: + await ctx.send("Counting has been reset.") + + @countset.command(name="role") + async def countset_role(self, ctx: commands.Context, role: typing.Optional[discord.Role]): + """Add a whitelisted role.""" + if not role: + await self.config.guild(ctx.guild).whitelist.clear() + await ctx.send(f"Whitelisted role has been deleted.") + else: + await self.config.guild(ctx.guild).whitelist.set(role.id) + await ctx.send(f"{role.name} has been whitelisted.") + + @countset.command(name="warnmsg") + async def countset_warnmsg( + self, + ctx: commands.Context, + on_off: typing.Optional[bool], + seconds: typing.Optional[int], + ): + """Toggle a warning message. + + If `on_off` is not provided, the state will be flipped. + Optionally add how many seconds the bot should wait before deleting the message (0 for not deleting). + """ + target_state = on_off or not (await self.config.guild(ctx.guild).warning()) + await self.config.guild(ctx.guild).warning.set(target_state) + if target_state: + if not seconds or seconds < 0: + seconds = 0 + await ctx.send("Warning messages are now enabled.") + else: + await ctx.send( + f"Warning messages are now enabled, will be deleted after {seconds} seconds." + ) + await self.config.guild(ctx.guild).seconds.set(seconds) + else: + await ctx.send("Warning messages are now disabled.") + + @countset.command(name="topic") + async def countset_topic(self, ctx: commands.Context, on_off: typing.Optional[bool]): + """Toggle counting channel's topic changing. + + If `on_off` is not provided, the state will be flipped.=""" + target_state = on_off or not (await self.config.guild(ctx.guild).topic()) + await self.config.guild(ctx.guild).topic.set(target_state) + if target_state: + await ctx.send("Updating the channel's topic is now enabled.") + else: + await ctx.send("Updating the channel's topic is now disabled.") + + @countset.command(name="settings") + async def countset_settings(self, ctx: commands.Context): + """See current settings.""" + data = await self.config.guild(ctx.guild).all() + channel = ctx.guild.get_channel(data["channel"]) + channel = channel.mention if channel else "None" + + goal = "None" if data["goal"] == 0 else str(data["goal"]) + + role = ctx.guild.get_role(data["whitelist"]) + role = role.name if role else "None" + + warn = "Disabled" if data["warning"] else f"Enabled ({data['seconds']} s)" + + embed = discord.Embed(colour=await ctx.embed_colour(), timestamp=datetime.datetime.now()) + embed.set_author(name=ctx.guild.name, icon_url=ctx.guild.icon_url) + embed.title = "**__Counting settings:__**" + embed.set_footer(text="*required to function properly") + + embed.add_field(name="Channel*:", value=channel) + embed.add_field(name="Whitelisted role:", value=role) + embed.add_field(name="Warning message:", value=warn) + embed.add_field(name="Next number:", value=str(data["previous"] + 1)) + embed.add_field(name="Goal:", value=goal) + embed.add_field(name="Topic changing:", value=str(data["topic"])) + + await ctx.send(embed=embed) + + @commands.Cog.listener() + async def on_message(self, message): + if not message.guild or message.author.id == self.bot.user.id: + return + if message.channel.id != await self.config.guild(message.guild).channel(): + return + last_id = await self.config.guild(message.guild).last() + previous = await self.config.guild(message.guild).previous() + seconds = await self.config.guild(message.guild).seconds() + if message.author.id != last_id: + try: + current = int(message.content) + if current - 1 == previous: + await self.config.guild(message.guild).previous.set(current) + await self.config.guild(message.guild).last.set(message.author.id) + if await self.config.guild(message.guild).topic(): + return await self._update_topic(message.channel) + return + except (TypeError, ValueError): + pass + rid = await self.config.guild(message.guild).whitelist() + if rid: + role = message.guild.get_role(int(rid)) + if role and role in message.author.roles: + return + if await self.config.guild(message.guild).warning(): + if message.author.id != last_id: + warn_msg = await message.channel.send( + f"The next message in this channel must be {previous + 1}" + ) + else: + warn_msg = await message.channel.send(f"You cannot count twice in a row.") + if seconds != 0: + await asyncio.sleep(seconds) + await warn_msg.delete() + try: + await message.delete() + except (discord.Forbidden, discord.NotFound): + pass + + @commands.Cog.listener() + async def on_message_delete(self, message): + if not message.guild: + return + if message.channel.id != await self.config.guild(message.guild).channel(): + return + try: + deleted = int(message.content) + previous = await self.config.guild(message.guild).previous() + goal = await self.config.guild(message.guild).goal() + if deleted == previous: + s = str(deleted) + if goal == 0: + msgs = await message.channel.history(limit=100).flatten() + else: + msgs = await message.channel.history(limit=goal).flatten() + msg = find(lambda m: m.content == s, msgs) + if not msg: + p = deleted - 1 + await self.config.guild(message.guild).previous.set(p) + await message.channel.send(deleted) + except (TypeError, ValueError): + return + + async def _update_topic(self, channel): + goal = await self.config.guild(channel.guild).goal() + prev = await self.config.guild(channel.guild).previous() + if goal != 0 and prev < goal: + await channel.edit( + topic=f"Let's count! | Next message must be {prev + 1}! | Goal is {goal}!" + ) + elif goal != 0 and prev == goal: + await channel.send("We've reached the goal! :tada:") + await channel.edit(topic=f"Goal reached! :tada:") + else: + await channel.edit(topic=f"Let's count! | Next message must be {prev + 1}!") diff --git a/counting/info.json b/counting/info.json new file mode 100644 index 000000000..86998c0ee --- /dev/null +++ b/counting/info.json @@ -0,0 +1,9 @@ +{ + "author" : ["saurichable", "Kreusada"], + "install_msg": "Thanks for installing, have fun. Please refer to my docs if you need any help: https://kreusadacogs.readthedocs.io/en/latest/cog_counting.html", + "name" : "Counting", + "short" : "Counting channel.", + "description" : "Make a counting channel with goals.", + "tags" : ["counting", "count"], + "end_user_data_statement": "This cog stores user IDs if they are the last one to count." +} \ No newline at end of file diff --git a/docs/cog_counting.rst b/docs/cog_counting.rst new file mode 100644 index 000000000..a32369e92 --- /dev/null +++ b/docs/cog_counting.rst @@ -0,0 +1,96 @@ +.. _counting: + +======== +Counting +======== + +This is the cog guide for the 'Counting' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 1.4.0. Ensure + that you are up to date by running ``[p]cog update counting``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Make a counting channel with goals. + +-------- +Commands +-------- + +Here are all the commands included in this cog (9): + ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| Command | Help | ++==========================+=======================================================================================================+ +| ``[p]countset`` | Various Counting settings. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset channel`` | Set the counting channel. | +| | | +| | If channel isn't provided, it will delete the current channel. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset goal`` | Set the counting goal. | +| | | +| | If goal isn't provided, it will be deleted. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset reset`` | Reset the counter and start from 0 again! | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset role`` | Add a whitelisted role. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset settings`` | See current settings. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset start`` | Set the starting number. | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset topic`` | Toggle counting channel's topic changing. | +| | | +| | If `on_off` is not provided, the state will be flipped.= | ++--------------------------+-------------------------------------------------------------------------------------------------------+ +| ``[p]countset warnmsg`` | Toggle a warning message. | +| | | +| | If `on_off` is not provided, the state will be flipped. | +| | Optionally add how many seconds the bot should wait before deleting the message (0 for not deleting). | ++--------------------------+-------------------------------------------------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Counting. + +.. code-block:: ini + + [p]cog install kreusada-cogs counting + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load counting + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/docs/cog_gallery.rst b/docs/cog_gallery.rst new file mode 100644 index 000000000..8e730c8ae --- /dev/null +++ b/docs/cog_gallery.rst @@ -0,0 +1,83 @@ +.. _gallery: + +======= +Gallery +======= + +This is the cog guide for the 'Gallery' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 2.0.0. Ensure + that you are up to date by running ``[p]cog update gallery``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Set channels as galleries, deleting all messages that don't contain any attachments. + +-------- +Commands +-------- + +Here are all the commands included in this cog (6): + ++----------------------------+-----------------------------------------------------------------------------+ +| Command | Help | ++============================+=============================================================================+ +| ``[p]galleryset`` | Various Gallery settings. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset add`` | Add a channel to the list of Gallery channels. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset remove`` | Remove a channel from the list of Gallery channels. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset role`` | Add or remove a whitelisted role. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset settings`` | See current settings. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset time`` | Set how long (in seconds!!) the bot should wait before deleting non images. | +| | | +| | 0 to reset (default time) | ++----------------------------+-----------------------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Gallery. + +.. code-block:: ini + + [p]cog install kreusada-cogs gallery + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load gallery + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/docs/cog_lock.rst b/docs/cog_lock.rst new file mode 100644 index 000000000..37b9e6d5b --- /dev/null +++ b/docs/cog_lock.rst @@ -0,0 +1,89 @@ +.. _lock: + +==== +Lock +==== + +This is the cog guide for the 'Lock' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 2.0.0. Ensure + that you are up to date by running ``[p]cog update lock``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Lock `@everyone` from sending messages in channels or the entire guild, and only allow Moderators to talk. + +-------- +Commands +-------- + +Here are all the commands included in this cog (10): + ++-------------------------+--------------------------------------------------------------+ +| Command | Help | ++=========================+==============================================================+ +| ``[p]lock`` | Lock `@everyone` from sending messages. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lock server`` | Lock `@everyone` from sending messages in the entire server. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset`` | Various Lock settings. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset ignore`` | Ignore a channel during server lock. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset perms`` | Set if you use roles to access channels. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset role`` | Set role that can lock channels. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset settings`` | See current settings. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset unignore`` | Remove channels from the ignored list. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]unlock`` | Unlock the channel for `@everyone`. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]unlock server`` | Unlock the entire server for `@everyone` | ++-------------------------+--------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Lock. + +.. code-block:: ini + + [p]cog install kreusada-cogs lock + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load lock + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/docs/cog_mentionable.rst b/docs/cog_mentionable.rst new file mode 100644 index 000000000..47b30ae91 --- /dev/null +++ b/docs/cog_mentionable.rst @@ -0,0 +1,73 @@ +.. _mentionable: + +=========== +Mentionable +=========== + +This is the cog guide for the 'Mentionable' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 2.0.0. Ensure + that you are up to date by running ``[p]cog update mentionable``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Very simple way to make unmentionable roles mentionable. + +-------- +Commands +-------- + +Here are all the commands included in this cog (2): + ++------------------+-------------------------------+ +| Command | Help | ++==================+===============================+ +| ``[p]mention`` | Makes that role mentionable | ++------------------+-------------------------------+ +| ``[p]unmention`` | Makes that role unmentionable | ++------------------+-------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Mentionable. + +.. code-block:: ini + + [p]cog install kreusada-cogs mentionable + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load mentionable + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/docs/cog_pick.rst b/docs/cog_pick.rst new file mode 100644 index 000000000..210824e78 --- /dev/null +++ b/docs/cog_pick.rst @@ -0,0 +1,76 @@ +.. _pick: + +==== +Pick +==== + +This is the cog guide for the 'Pick' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 1.0.0. Ensure + that you are up to date by running ``[p]cog update pick``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Pick a random member. + +-------- +Commands +-------- + +Here are all the commands included in this cog (2): + ++---------------+-------------------------------------------------------------------------------------------------+ +| Command | Help | ++===============+=================================================================================================+ +| ``[p]pick`` | Pick a random member. You may supply a role to pick from. | ++---------------+-------------------------------------------------------------------------------------------------+ +| ``[p]pickid`` | Pick a random member, displaying the ID only. You may supply a role to pick from. | +| | | +| | This can be integrated with [nestedcommands by tmerc](https://github.com/tmercswims/tmerc-cogs) | +| | Example of usage: `[p]say Congratulations <@$(pick True)>! You won!` | ++---------------+-------------------------------------------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Pick. + +.. code-block:: ini + + [p]cog install kreusada-cogs pick + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load pick + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/docs/index.rst b/docs/index.rst index 5a5084fa4..c10cd6f15 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,13 +30,18 @@ Useful Links cog_cogpaths cog_colour cog_consoleclearer + cog_counting cog_embedcreator cog_flags + cog_gallery + cog_lock + cog_mentionable cog_messagedeleter cog_minifier cog_morsecode cog_namegenerator cog_onthisday + cog_pick cog_pypi cog_qr cog_quotes @@ -50,6 +55,7 @@ Useful Links cog_timestamps cog_tonguetwisters cog_unicodelookup + cog_vinfo .. toctree:: :caption: Repository diff --git a/gallery/LICENSE.md b/gallery/LICENSE.md new file mode 100644 index 000000000..fa0086a95 --- /dev/null +++ b/gallery/LICENSE.md @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/gallery/README.rst b/gallery/README.rst new file mode 100644 index 000000000..8e730c8ae --- /dev/null +++ b/gallery/README.rst @@ -0,0 +1,83 @@ +.. _gallery: + +======= +Gallery +======= + +This is the cog guide for the 'Gallery' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 2.0.0. Ensure + that you are up to date by running ``[p]cog update gallery``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Set channels as galleries, deleting all messages that don't contain any attachments. + +-------- +Commands +-------- + +Here are all the commands included in this cog (6): + ++----------------------------+-----------------------------------------------------------------------------+ +| Command | Help | ++============================+=============================================================================+ +| ``[p]galleryset`` | Various Gallery settings. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset add`` | Add a channel to the list of Gallery channels. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset remove`` | Remove a channel from the list of Gallery channels. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset role`` | Add or remove a whitelisted role. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset settings`` | See current settings. | ++----------------------------+-----------------------------------------------------------------------------+ +| ``[p]galleryset time`` | Set how long (in seconds!!) the bot should wait before deleting non images. | +| | | +| | 0 to reset (default time) | ++----------------------------+-----------------------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Gallery. + +.. code-block:: ini + + [p]cog install kreusada-cogs gallery + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load gallery + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/gallery/__init__.py b/gallery/__init__.py new file mode 100644 index 000000000..fff824414 --- /dev/null +++ b/gallery/__init__.py @@ -0,0 +1,10 @@ +from redbot.core.bot import Red +from redbot.core.utils import get_end_user_data_statement + +from .gallery import Gallery + +__red_end_user_data_statement__ = get_end_user_data_statement(__file__) + + +async def setup(bot: Red): + await bot.add_cog(Gallery(bot)) diff --git a/gallery/gallery.py b/gallery/gallery.py new file mode 100644 index 000000000..ee749c4c6 --- /dev/null +++ b/gallery/gallery.py @@ -0,0 +1,138 @@ +import asyncio +import datetime +import logging +import re +import typing + +import discord +from redbot.core import Config, commands +from redbot.core.bot import Red +from redbot.core.utils.chat_formatting import humanize_list + +log = logging.getLogger("red.kreusada-cogs.gallery") + + +class Gallery(commands.Cog): + """ + Set channels as galleries, deleting all messages that don't contain any attachments. + """ + + __version__ = "2.0.0" + __author__ = "saurichable, Kreusada" + + def __init__(self, bot: Red): + self.bot = bot + self.config = Config.get_conf(self, identifier=564154651321346431, force_registration=True) + + self.config.register_guild(channels=[], whitelist=None, time=0) + + async def red_delete_data_for_user(self, **kwargs): + # nothing to delete + return + + def format_help_for_context(self, ctx: commands.Context) -> str: + context = super().format_help_for_context(ctx) + return f"{context}\n\nVersion: {self.__version__}\nAuthors: {self.__author__}" + + @commands.group() + @commands.guild_only() + @commands.admin() + @commands.bot_has_permissions(manage_messages=True) + async def galleryset(self, ctx: commands.Context): + """Various Gallery settings.""" + + @galleryset.command(name="add") + async def galleryset_add(self, ctx: commands.Context, channel: discord.TextChannel): + """Add a channel to the list of Gallery channels.""" + if channel.id not in await self.config.guild(ctx.guild).channels(): + async with self.config.guild(ctx.guild).channels() as channels: + channels.append(channel.id) + await ctx.send(f"{channel.mention} has been added into the Gallery channels list.") + else: + await ctx.send(f"{channel.mention} is already in the Gallery channels list.") + + @galleryset.command(name="remove") + async def galleryset_remove(self, ctx: commands.Context, channel: discord.TextChannel): + """Remove a channel from the list of Gallery channels.""" + if channel.id in await self.config.guild(ctx.guild).channels(): + async with self.config.guild(ctx.guild).channels() as channels: + channels.remove(channel.id) + await ctx.send(f"{channel.mention} has been removed from the Gallery channels list.") + else: + await ctx.send(f"{channel.mention} isn't in the Gallery channels list.") + + @galleryset.command(name="role") + async def galleryset_role(self, ctx: commands.Context, role: typing.Optional[discord.Role]): + """Add or remove a whitelisted role.""" + if not role: + await self.config.guild(ctx.guild).whitelist.clear() + await ctx.send("Whitelisted role has been deleted.") + else: + await self.config.guild(ctx.guild).whitelist.set(role.id) + await ctx.send(f"{role.name} has been whitelisted.") + + @galleryset.command(name="time") + async def galleryset_time(self, ctx: commands.Context, time: commands.positive_int): + """Set how long (in seconds!!) the bot should wait before deleting non images. + + 0 to reset (default time)""" + await self.config.guild(ctx.guild).time.set(time) + await ctx.send(f"I will wait {time} seconds before deleting messages that are not images.") + + @galleryset.command(name="settings") + async def galleryset_settings(self, ctx: commands.Context): + """See current settings.""" + data = await self.config.guild(ctx.guild).all() + + channels = [] + for c_id in data["channels"]: + c = ctx.guild.get_channel(c_id) + if c: + channels.append(c.mention) + channels = "None" if channels == [] else humanize_list(channels) + + role = ctx.guild.get_role(data["whitelist"]) + role = "None" if not role else role.name + + embed = discord.Embed(colour=await ctx.embed_colour(), timestamp=datetime.datetime.now()) + embed.set_author(name=ctx.guild.name, icon_url=ctx.guild.icon_url) + embed.title = "**__Unique Name settings:__**" + embed.set_footer(text="*required to function properly") + + embed.add_field(name="Gallery channels:", value=channels) + embed.add_field(name="Whitelisted role:", value=role) + embed.add_field(name="Wait time:", value=str(data["time"])) + + await ctx.send(embed=embed) + + @commands.Cog.listener() + async def on_message(self, message: discord.Message): + if not message.guild: + return + if message.channel.id not in await self.config.guild(message.guild).channels(): + return + if not message.attachments: + uris = re.findall( + "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", + message.content, + ) + if len(uris) == 1: + uri = "".join(uris) + uri = uri.split("?")[0] + parts = uri.split(".") + extension = parts[-1] + imageTypes = ["jpg", "jpeg", "tiff", "png", "gif", "bmp"] + if extension in imageTypes: + return + rid = await self.config.guild(message.guild).whitelist() + time = await self.config.guild(message.guild).time() + if rid: + role = message.guild.get_role(int(rid)) + if role and role in message.author.roles: + return + if time != 0: + await asyncio.sleep(time) + try: + await message.delete() + except discord.Forbidden: + log.warning("Unable to delete message in Gallery channel %s", message.channel.id) diff --git a/gallery/info.json b/gallery/info.json new file mode 100644 index 000000000..d628f8942 --- /dev/null +++ b/gallery/info.json @@ -0,0 +1,9 @@ +{ + "author" : ["saurichable", "Kreusada"], + "install_msg": "Thanks for installing, have fun. Please refer to my docs if you need any help: https://kreusadacogs.readthedocs.io/en/latest/cog_gallery.html", + "name" : "Gallery", + "short" : "Set channels as galleries, deleting all messages that don't contain any attachments.", + "description" : "Set channels as galleries, deleting all messages that don't contain any attachments.", + "tags" : ["gallery"], + "end_user_data_statement": "This cog does not store any user data." +} diff --git a/lock/LICENSE.md b/lock/LICENSE.md new file mode 100644 index 000000000..fa0086a95 --- /dev/null +++ b/lock/LICENSE.md @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/lock/README.rst b/lock/README.rst new file mode 100644 index 000000000..37b9e6d5b --- /dev/null +++ b/lock/README.rst @@ -0,0 +1,89 @@ +.. _lock: + +==== +Lock +==== + +This is the cog guide for the 'Lock' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 2.0.0. Ensure + that you are up to date by running ``[p]cog update lock``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Lock `@everyone` from sending messages in channels or the entire guild, and only allow Moderators to talk. + +-------- +Commands +-------- + +Here are all the commands included in this cog (10): + ++-------------------------+--------------------------------------------------------------+ +| Command | Help | ++=========================+==============================================================+ +| ``[p]lock`` | Lock `@everyone` from sending messages. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lock server`` | Lock `@everyone` from sending messages in the entire server. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset`` | Various Lock settings. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset ignore`` | Ignore a channel during server lock. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset perms`` | Set if you use roles to access channels. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset role`` | Set role that can lock channels. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset settings`` | See current settings. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]lockset unignore`` | Remove channels from the ignored list. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]unlock`` | Unlock the channel for `@everyone`. | ++-------------------------+--------------------------------------------------------------+ +| ``[p]unlock server`` | Unlock the entire server for `@everyone` | ++-------------------------+--------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Lock. + +.. code-block:: ini + + [p]cog install kreusada-cogs lock + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load lock + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/lock/__init__.py b/lock/__init__.py new file mode 100644 index 000000000..c15e522d1 --- /dev/null +++ b/lock/__init__.py @@ -0,0 +1,10 @@ +from redbot.core.bot import Red +from redbot.core.utils import get_end_user_data_statement + +from .lock import Lock + +__red_end_user_data_statement__ = get_end_user_data_statement(__file__) + + +async def setup(bot: Red): + await bot.add_cog(Lock(bot)) diff --git a/lock/info.json b/lock/info.json new file mode 100644 index 000000000..696dfe573 --- /dev/null +++ b/lock/info.json @@ -0,0 +1,9 @@ +{ + "author" : ["saurichable", "Kreusada"], + "install_msg": "Thanks for installing, have fun. Please refer to my docs if you need any help: https://kreusadacogs.readthedocs.io/en/latest/cog_lock.html", + "name" : "Lock", + "short" : "Lock `@everyone` from sending messages.", + "description" : "Lock `@everyone` from sending messages in channels or the entire guild, and only allow Moderators to talk.", + "tags" : ["lockdown", "lock"], + "end_user_data_statement": "This cog does not store any user data." +} diff --git a/lock/lock.py b/lock/lock.py new file mode 100644 index 000000000..952a57162 --- /dev/null +++ b/lock/lock.py @@ -0,0 +1,196 @@ +import datetime +import typing + +import discord +from redbot.core import Config, commands +from redbot.core.bot import Red +from redbot.core.utils.chat_formatting import humanize_list + + +class Lock(commands.Cog): + """ + Lock `@everyone` from sending messages in channels or the entire guild, and only allow Moderators to talk. + """ + + __version__ = "2.0.0" + __author__ = "saurichable, Kreusada" + + def __init__(self, bot: Red): + self.bot = bot + self.config = Config.get_conf(self, identifier=36546565165464, force_registration=True) + + self.config.register_guild(moderator=None, everyone=True, ignore=[]) + + async def red_delete_data_for_user(self, *, requester, user_id): + # nothing to delete + return + + def format_help_for_context(self, ctx: commands.Context) -> str: + context = super().format_help_for_context(ctx) + return f"{context}\n\nVersion: {self.__version__}\nAuthors : {self.__author__}" + + @commands.group(autohelp=True) + @commands.guild_only() + @commands.admin() + async def lockset(self, ctx: commands.Context): + """Various Lock settings.""" + + @lockset.command(name="role") + async def lockset_role(self, ctx: commands.Context, role: discord.Role): + """Set role that can lock channels.""" + await self.config.guild(ctx.guild).moderator.set(role.id) + await ctx.tick() + + @lockset.command(name="perms") + async def lockset_perms(self, ctx: commands.Context, everyone: bool): + """Set if you use roles to access channels.""" + await self.config.guild(ctx.guild).everyone.set(not everyone) + await ctx.tick() + + @lockset.command(name="ignore") + async def lockset_ignore(self, ctx: commands.Context, channel: discord.TextChannel): + """Ignore a channel during server lock.""" + if channel.id not in await self.config.guild(ctx.guild).ignore(): + async with self.config.guild(ctx.guild).ignore() as ignore: + ignore.append(channel.id) + return await ctx.send( + f"{channel.mention} has been added into the ignored channels list." + ) + await ctx.send(f"{channel.mention} is already in the ignored channels list.") + + @lockset.command(name="unignore") + async def lockset_unignore(self, ctx: commands.Context, channel: discord.TextChannel): + """Remove channels from the ignored list.""" + if channel.id not in await self.config.guild(ctx.guild).ignore(): + return await ctx.send(f"{channel.mention} already isn't in the ignored channels list.") + async with self.config.guild(ctx.guild).ignore() as ignore: + ignore.remove(channel.id) + await ctx.send(f"{channel.mention} has been removed from the ignored channels list.") + + @lockset.command(name="settings") + async def lockset_settings(self, ctx: commands.Context): + """See current settings.""" + data = await self.config.guild(ctx.guild).all() + mods = ctx.guild.get_role(data["moderator"]) + mods = "None" if not mods else mods.name + + channels = data["ignore"] + c_text = list() + if channels == []: + c_text = "None" + else: + for channel in channels: + c = ctx.guild.get_channel(channel) + if c: + c_text.append(c.mention) + c_text = humanize_list(c_text) + + embed = discord.Embed(colour=await ctx.embed_colour(), timestamp=datetime.datetime.now()) + embed.set_author(name=ctx.guild.name, icon_url=ctx.guild.icon_url) + embed.title = "**__Lock settings:__**" + embed.set_footer(text="*required to function properly") + + embed.add_field(name="Role that can type after locking*:", value=mods, inline=False) + embed.add_field( + name="Using roles to access servers:*:", + value=str(not data["everyone"]), + inline=False, + ) + embed.add_field(name="Ignored channels:", value=c_text, inline=False) + + await ctx.send(embed=embed) + + @commands.mod() + @commands.bot_has_permissions(manage_channels=True) + @commands.guild_only() + @commands.group(invoke_without_command=True) + async def lock(self, ctx: commands.Context): + """Lock `@everyone` from sending messages.""" + mods = ctx.guild.get_role(await self.config.guild(ctx.guild).moderator()) + which = await self.config.guild(ctx.guild).everyone() + + if not mods: + return await ctx.send("Uh oh. Looks like your Admins haven't setup this yet.") + if which: + await ctx.channel.set_permissions( + ctx.guild.default_role, read_messages=True, send_messages=False + ) + else: + await ctx.channel.set_permissions( + ctx.guild.default_role, read_messages=False, send_messages=False + ) + await ctx.channel.set_permissions(mods, read_messages=True, send_messages=True) + await ctx.send(":lock: Channel locked. Only Moderators can type.") + + @lock.command(name="server") + async def lock_server(self, ctx: commands.Context, confirmation: typing.Optional[bool]): + """Lock `@everyone` from sending messages in the entire server.""" + if not confirmation: + return await ctx.send( + "This will overwrite every channel's permissions.\n" + f"If you're sure, type `{ctx.clean_prefix}lockserver yes` (you can set an alias for this so I don't ask you every time)." + ) + async with ctx.typing(): + mods = ctx.guild.get_role(await self.config.guild(ctx.guild).moderator()) + which = await self.config.guild(ctx.guild).everyone() + ignore = await self.config.guild(ctx.guild).ignore() + + if not mods: + return await ctx.send("Uh oh. Looks like your Admins haven't setup this yet.") + for channel in ctx.guild.text_channels: + if channel.id in ignore: + continue + if which: + await channel.set_permissions( + ctx.guild.default_role, read_messages=True, send_messages=False + ) + else: + await channel.set_permissions( + ctx.guild.default_role, read_messages=False, send_messages=False + ) + await channel.set_permissions(mods, read_messages=True, send_messages=True) + await ctx.send(":lock: Server locked. Only Moderators can type.") + + @commands.mod() + @commands.bot_has_permissions(manage_channels=True) + @commands.guild_only() + @commands.group(invoke_without_command=True) + async def unlock(self, ctx: commands.Context): + """Unlock the channel for `@everyone`.""" + mods = ctx.guild.get_role(await self.config.guild(ctx.guild).moderator()) + which = await self.config.guild(ctx.guild).everyone() + + if not mods: + return await ctx.send("Uh oh. Looks like your Admins haven't setup this yet.") + if which: + await ctx.channel.set_permissions( + ctx.guild.default_role, read_messages=True, send_messages=True + ) + else: + await ctx.channel.set_permissions( + ctx.guild.default_role, read_messages=False, send_messages=True + ) + await ctx.send(":unlock: Channel unlocked.") + + @unlock.command(name="server") + async def unlock_server(self, ctx: commands.Context): + """Unlock the entire server for `@everyone`""" + async with ctx.typing(): + mods = ctx.guild.get_role(await self.config.guild(ctx.guild).moderator()) + which = await self.config.guild(ctx.guild).everyone() + ignore = await self.config.guild(ctx.guild).ignore() + + if not mods: + return await ctx.send("Uh oh. Looks like your Admins haven't setup this yet.") + for channel in ctx.guild.text_channels: + if channel.id in ignore: + continue + if which: + await channel.set_permissions( + ctx.guild.default_role, read_messages=True, send_messages=True + ) + else: + await channel.set_permissions( + ctx.guild.default_role, read_messages=False, send_messages=True + ) + await ctx.send(":unlock: Server unlocked.") diff --git a/mentionable/LICENSE.md b/mentionable/LICENSE.md new file mode 100644 index 000000000..fa0086a95 --- /dev/null +++ b/mentionable/LICENSE.md @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/mentionable/README.rst b/mentionable/README.rst new file mode 100644 index 000000000..47b30ae91 --- /dev/null +++ b/mentionable/README.rst @@ -0,0 +1,73 @@ +.. _mentionable: + +=========== +Mentionable +=========== + +This is the cog guide for the 'Mentionable' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 2.0.0. Ensure + that you are up to date by running ``[p]cog update mentionable``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Very simple way to make unmentionable roles mentionable. + +-------- +Commands +-------- + +Here are all the commands included in this cog (2): + ++------------------+-------------------------------+ +| Command | Help | ++==================+===============================+ +| ``[p]mention`` | Makes that role mentionable | ++------------------+-------------------------------+ +| ``[p]unmention`` | Makes that role unmentionable | ++------------------+-------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Mentionable. + +.. code-block:: ini + + [p]cog install kreusada-cogs mentionable + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load mentionable + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/mentionable/__init__.py b/mentionable/__init__.py new file mode 100644 index 000000000..fb884c4c8 --- /dev/null +++ b/mentionable/__init__.py @@ -0,0 +1,10 @@ +from redbot.core.bot import Red +from redbot.core.utils import get_end_user_data_statement + +from .mentionable import Mentionable + +__red_end_user_data_statement__ = get_end_user_data_statement(__file__) + + +async def setup(bot: Red): + await bot.add_cog(Mentionable(bot)) diff --git a/mentionable/info.json b/mentionable/info.json new file mode 100644 index 000000000..bcbaf141a --- /dev/null +++ b/mentionable/info.json @@ -0,0 +1,9 @@ +{ + "author" : ["saurichable", "bobloy", "Kreusada"], + "install_msg": "Thanks for installing, have fun. Please refer to my docs if you need any help: https://kreusadacogs.readthedocs.io/en/latest/cog_mentionable.html", + "name" : "Mentionable", + "short" : "Makes unmentionable roles mentionable.", + "description" : "Very simple way to make unmentionable roles mentionable.", + "tags" : ["mentionable"], + "end_user_data_statement": "This cog does not store any user data." +} diff --git a/mentionable/mentionable.py b/mentionable/mentionable.py new file mode 100644 index 000000000..b09c6a096 --- /dev/null +++ b/mentionable/mentionable.py @@ -0,0 +1,49 @@ +import discord +from redbot.core import commands +from redbot.core.bot import Red + + +class Mentionable(commands.Cog): + """ + Very simple way to make unmentionable roles mentionable. + """ + + __version__ = "2.0.0" + __author__ = "saurichable, Kreusada" + + def __init__(self, bot: Red): + self.bot = bot + + async def red_delete_data_for_user(self, *, requester, user_id): + # nothing to delete + return + + def format_help_for_context(self, ctx: commands.Context) -> str: + context = super().format_help_for_context(ctx) + return f"{context}\n\nVersion: {self.__version__}\nAuthors: {self.__author__}" + + @commands.admin() + @commands.command() + @commands.guild_only() + @commands.bot_has_permissions(manage_roles=True) + async def mention(self, ctx: commands.Context, *, role: discord.Role): + """Makes that role mentionable""" + if not role.mentionable: + await role.edit(mentionable=True) + await ctx.send(f"{role} is now mentionable.") + else: + await ctx.send(f"{role} is already mentionable.") + + @commands.admin() + @commands.command() + @commands.guild_only() + @commands.bot_has_permissions(manage_roles=True) + async def unmention(self, ctx: commands.Context, *, role: discord.Role): + """ + Makes that role unmentionable + """ + if not role.mentionable: + await ctx.send(f"{role} is already unmentionable.") + else: + await role.edit(mentionable=False) + await ctx.send(f"{role} is now unmentionable.") diff --git a/pick/LICENSE.md b/pick/LICENSE.md new file mode 100644 index 000000000..fa0086a95 --- /dev/null +++ b/pick/LICENSE.md @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/pick/README.rst b/pick/README.rst new file mode 100644 index 000000000..210824e78 --- /dev/null +++ b/pick/README.rst @@ -0,0 +1,76 @@ +.. _pick: + +==== +Pick +==== + +This is the cog guide for the 'Pick' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 1.0.0. Ensure + that you are up to date by running ``[p]cog update pick``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Pick a random member. + +-------- +Commands +-------- + +Here are all the commands included in this cog (2): + ++---------------+-------------------------------------------------------------------------------------------------+ +| Command | Help | ++===============+=================================================================================================+ +| ``[p]pick`` | Pick a random member. You may supply a role to pick from. | ++---------------+-------------------------------------------------------------------------------------------------+ +| ``[p]pickid`` | Pick a random member, displaying the ID only. You may supply a role to pick from. | +| | | +| | This can be integrated with [nestedcommands by tmerc](https://github.com/tmercswims/tmerc-cogs) | +| | Example of usage: `[p]say Congratulations <@$(pick True)>! You won!` | ++---------------+-------------------------------------------------------------------------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install Pick. + +.. code-block:: ini + + [p]cog install kreusada-cogs pick + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load pick + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/pick/__init__.py b/pick/__init__.py new file mode 100644 index 000000000..dbe0afac0 --- /dev/null +++ b/pick/__init__.py @@ -0,0 +1,57 @@ +import random +from typing import Optional + +import discord +from redbot.core import commands +from redbot.core.utils import get_end_user_data_statement +from redbot.core.utils.chat_formatting import inline + +__red_end_user_data_statement__ = get_end_user_data_statement(__file__) + + +class Pick(commands.Cog): + """Pick a random member.""" + + __version__ = "1.0.0" + __author__ = "Kreusada, saurichable, AAA3A" + + async def red_delete_data_for_user(self, **kwargs): + # nothing to delete + return + + def format_help_for_context(self, ctx: commands.Context) -> str: + context = super().format_help_for_context(ctx) + return f"{context}\n\nVersion: {self.__version__}\nAuthors : {self.__author__}" + + @commands.command() + @commands.guild_only() + async def pick(self, ctx: commands.Context, *, role: Optional[discord.Role] = None): + """Pick a random member. You may supply a role to pick from.""" + role = role or ctx.guild.default_role + winner = random.choice(role.members) + embed = discord.Embed( + description=f"- Mention: {winner.mention} ({inline(winner.mention)})\n- ID: {winner.id}", + colour=await ctx.embed_colour(), + ) + embed.set_image(url=winner.banner.url if winner.banner else None) + embed.add_field( + name="Chosen amongst:", + value=f"{role.mention} ({role.id})" if role != ctx.guild.default_role else "Everyone", + ) + embed.set_author(name=winner, icon_url=winner.avatar.url if winner.avatar else None) + await ctx.send(embed=embed) + + @commands.command() + @commands.guild_only() + async def pickid(self, ctx: commands.Context, *, role: Optional[discord.Role] = None): + """Pick a random member, displaying the ID only. You may supply a role to pick from. + + This can be integrated with [nestedcommands by tmerc](https://github.com/tmercswims/tmerc-cogs) + Example of usage: `[p]say Congratulations <@$(pick True)>! You won!` + """ + await ctx.send(str(random.choice((role or ctx.guild.default_role).members).id)) + + +async def setup(bot): + cog = Pick() + await bot.add_cog(cog) diff --git a/pick/info.json b/pick/info.json new file mode 100644 index 000000000..8a9347c04 --- /dev/null +++ b/pick/info.json @@ -0,0 +1,9 @@ +{ + "author" : ["Kreusada", "saurichable", "AAA3A"], + "install_msg": "Thanks for installing, have fun. Please refer to my docs if you need any help: https://kreusadacogs.readthedocs.io/en/latest/cog_pick.html", + "name" : "Pick", + "short" : "Pick a random member.", + "description" : "Pick a random member.", + "tags" : ["pick", "random", "member", "nestedcommands"], + "end_user_data_statement": "This cog does not store any user data." +} diff --git a/pyproject.toml b/pyproject.toml index 28ee7875d..7fef1e290 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,13 +29,18 @@ 'cogpaths', 'colour', 'consoleclearer', + 'counting', 'embedcreator', 'flags', + 'gallery', + 'lock', + 'mentionable', 'messagedeleter', 'minifier', 'morsecode', 'namegenerator', 'onthisday', + 'pick', 'pypi', 'qr', 'quotes',