Created
May 18, 2019 17:31
-
-
Save Malarne/e35d803ecc867c2065c7ad221f54e1d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from redbot.core import checks, Config | |
import discord | |
from redbot.core import commands | |
import asyncio | |
import datetime | |
from redbot.core.i18n import Translator, cog_i18n | |
_ = Translator("Anarchy", __file__) | |
@cog_i18n | |
class Anarchy(commands.Cog): | |
def __init__(self, bot): | |
self.bot = bot | |
self.config = Config.get_conf(self, identifier=971109711499104121) | |
default_member = { | |
"votes": 0, | |
"messages": 0 | |
} | |
default_guild = { | |
"modrole": None, | |
"cooldown": 1, | |
"threshold": 30 #Note that i have no idea on how much i should put by default, so better modify that depending on your needs | |
} | |
default_channel = { | |
"ignored": False | |
} | |
self.config.register_member(**default_member) | |
self.config.register_guild(**default_guild) | |
self.config.register_channel(**default_channel) | |
def anarcheck(self): | |
async def predicate(ctx): | |
perm = ctx.me.guild_permissions | |
if perm.kick_members and perm.ban_members: | |
return True | |
else: | |
return False | |
return predicate | |
async def get_power(self, member): | |
### 3 next lines taken from Aikaterna's joinleave cog | |
join_date = datetime.datetime.strptime(str(member.created_at), "%Y-%m-%d %H:%M:%S.%f") | |
now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) | |
since_join = now - join_date | |
days = since_join.days | |
months = days%30 | |
msgs = await self.config.member(member).messages() | |
ratio = msgs /10000 | |
if months == 0: | |
return 0.5 * ratio | |
elif months <= 2: | |
return 1 * ratio | |
elif months <= 6: | |
return 2 * ratio | |
else: | |
return 3 * ratio | |
@commands.group() | |
@anarcheck | |
async def anarchy(self, ctx): | |
"""Commands for anarchy cog.""" | |
pass | |
@anarchy.group() | |
@checks.mod() | |
@anarcheck | |
async def anarchyset(self, ctx): | |
"""Configuration command for the anarchy cog.""" | |
pass | |
@anarchyset.command(name="role") | |
@checks.mod() | |
@anarcheck | |
async def set_role(self, ctx, role : discord.Role): | |
"""Set the role given to people elected as moderators.""" | |
await self.config.guild(ctx.guild).modrole.set(role.id) | |
await ctx.send(_("Mod role successfully set to {0.id}.").format(role)) | |
@anarchyset.command(name="threshold") | |
@checks.mod() | |
@anarcheck | |
async def set_threshold(self, ctx, threshold : int): | |
"""Modify the threshold needed to get mod role.""" | |
await self.config.guild(ctx.guild).modrole.set(threshold) | |
await ctx.send(_("Server threshold successfully set to {} points.").format(threshold)) | |
@anarchyset.command(name="cooldown") | |
@checks.mod() | |
@anarcheck | |
async def set_cooldown(self, ctx, cooldown : int = 1): | |
"""Modify the cooldown between 2 counted messages. | |
This settings is meant to not allow spammers to get any advantage. | |
Default to 1 sec.""" | |
await self.config.guild(ctx.guild).cooldown.set(cooldown) | |
await ctx.send(_("Cooldown successfully set to {} seconds.").format(cooldown)) | |
@anarchyset.command(name="ignore") | |
@checks.mod() | |
@anarcheck | |
async def ignore_channel(self, ctx, channels : commands.Greedy[discord.TextChannel]): | |
for i in channels: | |
await self.config.channel(i).ignore.set(True) | |
await ctx.send(_("Channels {} successfully ignored.").format(" ".join([x.mention for x in channels]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment