Browse Source

slowmode is working now woo

tags/v1.3.0
roxie 6 years ago
parent
commit
2d3d380456
5 changed files with 58 additions and 5 deletions
  1. +3
    -0
      checks.py
  2. +50
    -1
      cogs/admin.py
  3. +1
    -1
      config/cogs.py
  4. +1
    -1
      config/servers.json
  5. +3
    -2
      main.py

+ 3
- 0
checks.py View File

@@ -1,6 +1,7 @@
from discord.ext import commands
import load_config
from config.server_config import ServerConfig
import discord

def is_bot_owner():
return commands.check(lambda ctx: ctx.message.author.id == load_config.owner)
@@ -19,3 +20,5 @@ def is_owner_or_admin():
def is_nfsw_enabled():
return commands.check(lambda ctx: ServerConfig().load_config()[ctx.message.server.id]["nsfw"]["enabled"] == 1)

def not_pm():
return commands.check(lambda ctx: ctx.message.channel.type != discord.ChannelType.private)

+ 50
- 1
cogs/admin.py View File

@@ -1,8 +1,8 @@
import datetime
import checks
import discord
from discord.ext.commands import bot

import checks

class Admin():
"""
@@ -10,6 +10,53 @@ class Admin():
"""
def __init__(self, Bot):
self.bot = Bot
self.slow_mode = False
self.slow_mode_channels = {}
self.users = {}

async def on_message(self, message):
# Slow Mode Code
channel = message.channel
author = message.author

if not author == self.bot.user:
if self.slow_mode and channel.id in self.slow_mode_channels:
if author.id not in self.users[channel.id]:
# If user hasn't sent a message in this channel after slow mode was turned on
self.users[channel.id][author.id] = message.timestamp
else:
# Else, check when their last message was and if time is smaller than the timer, delete the message.
timer = datetime.timedelta(seconds=self.slow_mode_channels[channel.id])
if message.timestamp - self.users[channel.id][author.id] < timer:
await self.bot.delete_message(message)
else:
self.users[message.channel.id][author.id] = message.timestamp
else:
pass

@checks.not_pm()
@checks.is_owner_or_admin()
@bot.command(pass_context=True)
async def slowmode(self, ctx, time):
if time == "off" and self.slow_mode: # Turn Slow Mode off
self.slow_mode = False
self.slow_mode_channels.pop(ctx.message.channel.id)
self.users.pop(ctx.message.channel.id)
return await self.bot.say("Slowmode off")

elif time.isdigit() and not self.slow_mode: # Turn Slow Mode On
self.users[ctx.message.channel.id] = {}
self.slow_mode_channels[ctx.message.channel.id] = int(time)
self.slow_mode = True
return await self.bot.say("Slowmode on :snail: ({} seconds)".format(time))

elif time.isdigit and self.slow_mode: # Change value of Slow Mode timer
self.slow_mode_channels[ctx.message.channel.id] = int(time)
return await self.bot.say("Slowmode set to :snail: ({} seconds)".format(time))

else:
pass


@checks.is_owner_or_admin()
@bot.command(pass_context=True)
@@ -92,5 +139,7 @@ class Admin():





def setup(Bot):
Bot.add_cog(Admin(Bot))

+ 1
- 1
config/cogs.py View File

@@ -9,5 +9,5 @@ cogs = [
"cogs.settings",
"cogs.twitch",
"cogs.util",
"cogs.gss"
]

+ 1
- 1
config/servers.json View File

@@ -1 +1 @@
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "hellow", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0, "channels": []}, "admin_role": {"role": ""}, "custom_commands": {"0": {"test": "\"testedit\"", "hello": "<:tingles:346838411639914506>", "benis": "\ud83c\udd71enis", "sophie": "<@136619052994002944>", "myra": "<@342213251372941312>", "roxieee": "<@!142735312626515979>", "customs": "\"\ud83d\udec3\"", "zzz": "\ud83d\udca4", "lewd!": "\ud83d\udea8 lewd! \ud83d\udea8"}, "1": {}}, "perm_roles": {"admin": [], "mod": []}, "gss": {"logging_channel": "339201847678074880", "required_days": "5", "required_score": "3000000", "log_channel": ""}}, "395632940328943616": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": ""}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "298647714302787595": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "342276593009557514": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "358418840872419328": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "393764974444675073": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "5", "required_score": "2000"}}}
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "hellow", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0, "channels": []}, "admin_role": {"role": ""}, "custom_commands": {"0": {"test": "\"testedit\"", "hello": "<:tingles:346838411639914506>", "benis": "\ud83c\udd71enis", "sophie": "<@136619052994002944>", "myra": "<@342213251372941312>", "roxieee": "<@!142735312626515979>", "customs": "\"\ud83d\udec3\"", "zzz": "\ud83d\udca4", "lewd!": "\ud83d\udea8 lewd! \ud83d\udea8"}, "1": {}}, "perm_roles": {"admin": ["334078005347483648"], "mod": []}, "gss": {"logging_channel": "339201847678074880", "required_days": "5", "required_score": "3000000", "log_channel": ""}}, "395632940328943616": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": ""}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "298647714302787595": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "342276593009557514": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "358418840872419328": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "", "required_score": ""}}, "393764974444675073": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "nsfw": {"enabled": 0, "channels": []}, "perm_roles": {"admin": [], "mod": []}, "custom_commands": {"0": {}, "1": {}}, "gss": {"log_channel": "", "required_days": "5", "required_score": "2000"}}}

+ 3
- 2
main.py View File

@@ -1,4 +1,5 @@
#!/usr/env python
#!/usr/env python3

import time
import logging
import os.path
@@ -118,7 +119,7 @@ async def on_command_error(error, ctx):
embed.add_field(name='Message', value=ctx.message.content)
embed.timestamp = datetime.datetime.utcnow()
try:
await bot.send_message(load_config.owner, embed=embed)
await bot.send_message(discord.utils.get(ctx.message.server.members, id=load_config.owner, embed=embed))
except:
raise error
#else:

Loading…
Cancel
Save