Ejemplo n.º 1
0
    async def slowmode(
        self,
        ctx,
        *,
        interval: commands.TimedeltaConverter(
            minimum=timedelta(seconds=0),
            maximum=timedelta(hours=6),
            default_unit="seconds") = timedelta(seconds=0),
    ):
        """Changes channel's slowmode setting.

        Interval can be anything from 0 seconds to 6 hours.
        Use without parameters to disable.
        """
        modplus = ctx.bot.get_cog("ModPlus")
        if not await modplus.action_check(ctx, "editchannel"):
            return
        seconds = interval.total_seconds()
        await ctx.channel.edit(slowmode_delay=seconds)
        if seconds > 0:
            await ctx.send(
                _("Slowmode interval is now {interval}.").format(
                    interval=humanize_timedelta(timedelta=interval)))
        else:
            await ctx.send(_("Slowmode has been disabled."))
        await modplus.notify('editchannel',
                             f"{ctx.channel} has slowmode enabled.")
Ejemplo n.º 2
0
    async def cooldown_set(
        self,
        ctx,
        job,
        *,
        time: commands.TimedeltaConverter(
            minimum=datetime.timedelta(seconds=0),
            maximum=datetime.timedelta(days=2),
            default_unit="minutes",
        ),
    ):
        """Set the cooldown for the work, crime or rob commands. Minimum cooldown is 30 seconds.

        The time can be formatted as so `1h30m` etc. Valid times are hours, minutes and seconds.
        """
        job = job.lower()
        if job not in ["work", "crime", "rob", "deposit", "withdraw"]:
            return await ctx.send("Invalid job.")
        seconds = time.total_seconds()
        if seconds < 30:
            return await ctx.send("The miniumum interval is 30 seconds.")
        conf = await self.configglobalcheck(ctx)
        async with conf.cooldowns() as cooldowns:
            jobcd = {
                "work": "workcd",
                "crime": "crimecd",
                "rob": "robcd",
                "deposit": "depositcd",
                "withdraw": "withdrawcd",
            }
            cooldowns[jobcd[job]] = int(seconds)
        await ctx.tick()
Ejemplo n.º 3
0
 async def time(
     self,
     ctx,
     time: commands.TimedeltaConverter(
         minimum=datetime.timedelta(seconds=30),
         maximum=datetime.timedelta(minutes=5),
         default_unit="seconds",
     ),
 ):
     """Set the time for roulette wheel to start spinning."""
     seconds = time.total_seconds()
     conf = await self.configglobalcheck(ctx)
     await conf.roulette_time.set(seconds)
     await ctx.tick()
Ejemplo n.º 4
0
 async def frequency(
     self,
     ctx: commands.Context,
     frequency: commands.TimedeltaConverter(
         minimum=datetime.timedelta(minutes=5),
         maximum=datetime.timedelta(days=30),
         default_unit="minutes",
     ),
 ):
     """Set the frequency that UpdateNotify should check for updates."""
     await self.config.frequency.set(frequency.total_seconds())
     await ctx.send(
         checkmark("Update check frequency has been set to {}.".format(
             humanize_timedelta(timedelta=frequency))))
     self.enable_bg_loop()
Ejemplo n.º 5
0
 async def frequency(
     self,
     ctx: commands.Context,
     frequency: commands.TimedeltaConverter(
         minimum=timedelta(seconds=60),
         maximum=timedelta(days=30),
         default_unit="seconds",
     ),
 ):
     """Set the frequency Heartbeat will send pings."""
     await self.config.frequency.set(frequency.total_seconds())
     await ctx.send(
         checkmark("Heartbeat frequency has been set to {}.".format(
             humanize_timedelta(timedelta=frequency))))
     self.enable_bg_loop()
Ejemplo n.º 6
0
 async def cooldown_set(
     self,
     ctx,
     job,
     time: commands.TimedeltaConverter(
         minimum=datetime.timedelta(seconds=0),
         maximum=datetime.timedelta(days=2),
         default_unit="minutes",
     ),
 ):
     """Set the cooldown for the work, crime or rob commands. Minimum cooldown is 30 seconds."""
     if job not in ["work", "crime", "rob"]:
         return await ctx.send("Invalid job.")
     seconds = time.total_seconds()
     if seconds < 30:
         return await ctx.send("The miniumum interval is 30 seconds.")
     jobcd = {"work": "workcd", "crime": "crimecd", "rob": "robcd"}
     conf = await self.configglobalcheck(ctx)
     async with conf.cooldowns() as cooldowns:
         cooldowns[jobcd[job]] = int(seconds)
     await ctx.tick()
Ejemplo n.º 7
0
    async def slowmode(
        self,
        ctx,
        *,
        interval: commands.TimedeltaConverter(
            minimum=timedelta(seconds=0),
            maximum=timedelta(hours=6),
            default_unit="seconds") = timedelta(seconds=0),
    ):
        """Changes channel's slowmode setting.

        Interval can be anything from 0 seconds to 6 hours.
        Use without parameters to disable.
        """
        seconds = interval.total_seconds()
        await ctx.channel.edit(slowmode_delay=seconds)
        if seconds > 0:
            await ctx.send(
                _("Slowmode interval is now {interval}.").format(
                    interval=humanize_timedelta(timedelta=interval)))
        else:
            await ctx.send(_("Slowmode has been disabled."))
Ejemplo n.º 8
0
    async def defaultduration(
        self,
        ctx: commands.Context,
        *,
        duration: commands.TimedeltaConverter(minimum=timedelta(seconds=1),
                                              default_unit="seconds"),
    ):
        """Set the default time to be used when a user is tempbanned.

        Accepts: seconds, minutes, hours, days, weeks
        `duration` must be greater than zero.

        Examples:
            `[p]modset defaultduration 7d12h10m`
            `[p]modset defaultduration 7 days 12 hours 10 minutes`
        """
        guild = ctx.guild
        await self.config.guild(guild).default_tempban_duration.set(
            duration.total_seconds())
        await ctx.send(
            _("The default duration for tempbanning a user is now {duration}."
              ).format(duration=humanize_timedelta(timedelta=duration)))
Ejemplo n.º 9
0
# Default Library.
import asyncio
import datetime as dt
from collections import Counter, defaultdict
from typing import List

# Used by Red.
import discord
from redbot.core import commands
from redbot.core import checks, Config
from redbot.core.bot import Red
from redbot.core.commands import Cog, Context
from redbot.core.utils.chat_formatting import humanize_timedelta

POLL_TIMEDELTA_CONVERTER = commands.TimedeltaConverter(
    minimum=dt.timedelta(seconds=15),
    maximum=dt.timedelta(minutes=30),
    default_unit="seconds")


class StatusPoll(Cog):
    """Poll a question through people's custom statuses"""
    __author__ = "#s#8059"

    ERROR = ":x: Error: "
    HASH_ERROR = ERROR + "Don't include the # in the tag. The command will add it for you."
    NO_RESPONSE = "**Results:** Nobody voted!"
    POLL_END = "---\n\nPoll ended! Results:\n"
    OPEN_POLL_START = "**{q}**\nVote by changing your custom status, with **#{ht}** at the end! You have {time}."
    MC_POLL_START = "**{q}**\nVote by setting your custom status to the number of choice, " \
                    "with **#{ht}** at the end! You have {time}. Options:\n{lst}"
    MC_ONE_OPTION = ERROR + "We're not in North Korea, please provide more than one option."
Ejemplo n.º 10
0
# Default Library.
import csv
import datetime as dt
import re

# Required by Red.
import discord
import redbot.core.utils.menus as red_menu
from redbot.core import checks, commands, Config, data_manager
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import humanize_timedelta

SLOWMODE_TIMEDELTA_CONVERTER = commands.TimedeltaConverter(
    minimum=dt.timedelta(seconds=0),
    maximum=dt.timedelta(hours=6),
    default_unit="seconds")


class FixedVarious(commands.Cog):
    """Various commands that cannot be classified under any other modules"""
    __author__ = "#s#8059"

    ROLE_ROW = "`{:0{}d}` {} • **{}**"
    GOTO_LINK = "<https://discordapp.com/channels/{gld_id}/{chn_id}/{msg_id}>"
    DELIMITED_TOO_LONG = ":x: Error: the delimiter must be exactly one character."
    GUILD_NO_ROLES = ":x: Error: This server has no roles."
    SLOWMODE_SET = ":white_check_mark: The slowmode in {} has been set to {}."
    SLOWMODE_OFF = ":put_litter_in_its_place: The slowmode in {} has been disabled."
    SLOWMODE_NO_PERMS = ":x: Error: I need Manage Channel permissions in {} to set a slowmode!"

    def __init__(self, bot: Red):
Ejemplo n.º 11
0
    async def contestcount(
            self,
            ctx,
            channel: discord.TextChannel,
            emote: str,
            show_invalid: bool = True,
            voter_server_age: commands.TimedeltaConverter() = None,
            entries_per_page: int = 9,
            *other_emotes):
        timenow = datetime.now()

        def valid_user_vote(u):
            if (not hasattr(u, 'joined_at')) or u.joined_at is None:
                return False
            elif (not voter_server_age is None) and (
                    u.joined_at >= timenow - voter_server_age):
                return False
            return True

        entries = []
        async for message in channel.history():
            entry = {
                "name": str(message.author),
                "valid_votes": 0,
                "invalid_votes": 0
            }
            for r in message.reactions:
                if str(r.emoji) == emote or str(r.emoji) in other_emotes:
                    all_votes = await r.users().flatten()
                    entry["valid_votes"] = len(
                        list(filter(valid_user_vote, all_votes)))
                    entry["invalid_votes"] = len(
                        all_votes) - entry["valid_votes"]
            entries.append(entry)

        if len(entries) == 0:
            await ctx.send(f"No entris found for channel {channel}")
        else:
            entries = sorted(entries,
                             key=lambda e: e["valid_votes"],
                             reverse=True)

            pages = []
            embed = None
            for (i, entry) in enumerate(entries):
                if i % entries_per_page == 0:
                    if not embed is None:
                        pages.append(embed)
                    embed = discord.Embed.from_dict(
                        {"description": f"Contest leaderboard!"})
                if show_invalid:
                    embed.add_field(
                        name=f"#{i+1} {entry['name']}",
                        value=
                        f"{entry['valid_votes']} valid votes ({entry['invalid_votes']} invalid)",
                        inline=False)
                else:
                    embed.add_field(name=f"#{i+1} {entry['name']}",
                                    value=f"{entry['valid_votes']} votes",
                                    inline=False)

            pages.append(embed)

            await menus.menu(ctx, pages, menus.DEFAULT_CONTROLS)