Skip to content

Instantly share code, notes, and snippets.

@LostLuma
Created June 4, 2021 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LostLuma/a928d953a096b39d5bcc2868fba2c578 to your computer and use it in GitHub Desktop.
Save LostLuma/a928d953a096b39d5bcc2868fba2c578 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Mousey: Discord Moderation Bot
Copyright (C) 2016 - 2021 Lilly Rose Berner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import asyncio
import collections
import time
import discord
from ... import PURRL, Plugin
from ...utils import create_task
PLACE_COOLDOWN = 30
EVENT_CATEGORY = 840196581478891580
EVENT_REWARD_ROLE = 840245841729421354
class Blurple(Plugin):
def __init__(self, mousey):
super().__init__(mousey)
self._placed = collections.defaultdict(int)
self._counts = collections.defaultdict(int)
@Plugin.listener()
async def on_message(self, message):
if message.channel.category_id != EVENT_CATEGORY:
return
if not message.content.lower().startswith('p/place'):
return
now = time.monotonic()
before = self._placed.get(message.author.id, 0)
if now - before < PLACE_COOLDOWN:
return
self._counts[message.author.id] += 1
self._placed[message.author.id] = now
create_task(self.send_reminder(message))
if self._counts[message.author.id] >= 25 and not any(x.id == EVENT_REWARD_ROLE for x in message.author.roles):
await message.author.add_roles(discord.Object(id=EVENT_REWARD_ROLE), reason='Event participation')
async def send_reminder(self, message):
await asyncio.sleep(PLACE_COOLDOWN)
await message.channel.send(
f'You can place another pixel {message.author.mention} {PURRL}!',
allowed_mentions=discord.AllowedMentions(users=[message.author]),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment