Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe0a74cfc4 | ||
|
|
5bed587da9 | ||
|
|
f7a40f83a9 | ||
|
|
a66bc4982f | ||
|
|
04051eeacc | ||
|
|
8c2b3fa487 | ||
|
|
62e89960f7 |
@@ -2,9 +2,6 @@
|
|||||||
Defines cog for guild listeners. Contains functions for various guild events.
|
Defines cog for guild listeners. Contains functions for various guild events.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
import nextcord
|
import nextcord
|
||||||
|
|
||||||
@@ -20,7 +17,6 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_guild_join(self, guild: nextcord.Guild):
|
async def on_guild_join(self, guild: nextcord.Guild):
|
||||||
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
|
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
|
||||||
# turning guild id into string because json doesn't support ints as object keys.
|
|
||||||
highscores_data.add_new_server(guild.id)
|
highscores_data.add_new_server(guild.id)
|
||||||
|
|
||||||
welcome_message: str = "Hello, I keep track of Highscores for you!"
|
welcome_message: str = "Hello, I keep track of Highscores for you!"
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Defines cog for on message listener.
|
Defines cog for on message listener.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
@@ -22,7 +24,19 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
|||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message(self, message: nextcord.Message):
|
async def on_message(self, message: nextcord.Message):
|
||||||
"""Listener for message creation. Adds score and attachments to submission."""
|
"""Listener for message creation. Adds score and attachments to submission."""
|
||||||
|
# don't want to process any messages from bot.
|
||||||
|
if message.author.id == self.bot.user.id:
|
||||||
|
return
|
||||||
|
|
||||||
guild_id = message.guild.id
|
guild_id = message.guild.id
|
||||||
|
|
||||||
|
# troll addition for friends birthday
|
||||||
|
if guild_id == 239758371358638080 and date.today() == date(2022, 7, 31):
|
||||||
|
# 5% chance to send the message
|
||||||
|
chance = random.randint(1, 20)
|
||||||
|
if chance == 1:
|
||||||
|
await message.channel.send("Happy Birthday Chris <@642330132958281750>")
|
||||||
|
|
||||||
if message.author.id in submission_objects:
|
if message.author.id in submission_objects:
|
||||||
message_id = submission_objects[message.author.id]["message_id"]
|
message_id = submission_objects[message.author.id]["message_id"]
|
||||||
submission_channel_id = highscores_data.get_guild_submission_channel(guild_id)
|
submission_channel_id = highscores_data.get_guild_submission_channel(guild_id)
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"""
|
||||||
|
Functions for controlling the bot's presence.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
from nextcord.ext import commands
|
||||||
|
from nextcord.ext import tasks
|
||||||
|
import nextcord
|
||||||
|
|
||||||
|
|
||||||
|
class BotPresence(commands.Cog, name="Bot Presence"):
|
||||||
|
"""Class for bot presence functions."""
|
||||||
|
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_guild_join(self, guild: nextcord.Guild): # pylint: disable=unused-argument
|
||||||
|
"""Listener for Guild Join. Updated presence on guild join."""
|
||||||
|
await self.change_presence()
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
"""Starts the loop when bot is ready."""
|
||||||
|
await self.bot.wait_until_ready()
|
||||||
|
# pylint doesn't recognize that periodic_change_presense is subclassed from tasks.loop.
|
||||||
|
self.periodic_change_presence.start() # pylint: disable=no-member
|
||||||
|
|
||||||
|
@tasks.loop(minutes=2)
|
||||||
|
async def periodic_change_presence(self):
|
||||||
|
"""Loops every 2 minutes and changes presence."""
|
||||||
|
await self.change_presence()
|
||||||
|
|
||||||
|
async def change_presence(self):
|
||||||
|
"""Randomly chooses a presence and updates bot's presence."""
|
||||||
|
statuses = [
|
||||||
|
f"?help | {len(self.bot.guilds)} servers",
|
||||||
|
f"Vuln Pls. | {len(self.bot.guilds)} servers",
|
||||||
|
f"All your base are belong to us. | {len(self.bot.guilds)} servers",
|
||||||
|
f"Double plus good. | {len(self.bot.guilds)} servers",
|
||||||
|
]
|
||||||
|
|
||||||
|
status = random.choice(statuses)
|
||||||
|
|
||||||
|
await self.bot.change_presence(activity=nextcord.Game(status))
|
||||||
|
|
||||||
|
|
||||||
|
# This function will be called when this extension is loaded.
|
||||||
|
# It is necessary to add these functions to the bot.
|
||||||
|
def setup(bot: commands.Bot):
|
||||||
|
"""Adds function to bot"""
|
||||||
|
bot.add_cog(BotPresence(bot))
|
||||||
@@ -236,7 +236,7 @@ class SubmissionView(nextcord.ui.View):
|
|||||||
bot: commands.Bot,
|
bot: commands.Bot,
|
||||||
submission_user: int,
|
submission_user: int,
|
||||||
*,
|
*,
|
||||||
timeout: Optional[float] = 180,
|
timeout: Optional[float] = 300,
|
||||||
):
|
):
|
||||||
super().__init__(timeout=timeout)
|
super().__init__(timeout=timeout)
|
||||||
self._submission_user = submission_user
|
self._submission_user = submission_user
|
||||||
@@ -264,4 +264,13 @@ class SubmissionView(nextcord.ui.View):
|
|||||||
self.add_item(SubmitButton(self._bot))
|
self.add_item(SubmitButton(self._bot))
|
||||||
|
|
||||||
async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
|
async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
|
||||||
return self._submission_user == interaction.user.id
|
check = self._submission_user == interaction.user.id
|
||||||
|
|
||||||
|
if not check:
|
||||||
|
await interaction.send("This is not your submission.", ephemeral=True)
|
||||||
|
|
||||||
|
return check
|
||||||
|
|
||||||
|
async def on_timeout(self) -> None:
|
||||||
|
# remove user from submission objects after time out. Allows user to start new submission.
|
||||||
|
submission_objects.pop(self._submission_user)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"tables": {
|
"tables": {
|
||||||
"The Ambassador": [
|
"The Ambassador": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
],
|
],
|
||||||
"Astellarn": [
|
"Astellarn": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
@@ -42,8 +42,8 @@
|
|||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
],
|
],
|
||||||
"Black Stone Dragon": [
|
"Black Stone Dragon": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
@@ -65,8 +65,8 @@
|
|||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
],
|
],
|
||||||
"Crassian Leviathan": [
|
"Crassian Leviathan": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
@@ -160,8 +160,8 @@
|
|||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
],
|
],
|
||||||
"Masuta the Ascended": [
|
"Masuta the Ascended": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
@@ -193,15 +193,15 @@
|
|||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
],
|
],
|
||||||
"The Sanctum Guardian": [
|
"The Sanctum Guardian": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
],
|
],
|
||||||
"Seiryu the Azure Serpent": [
|
"Seiryu the Azure Serpent": [
|
||||||
"Kill Count",
|
"Solo Kill Count",
|
||||||
"Kill Time",
|
"Solo Kill Time",
|
||||||
"Group Kill Count",
|
"Group Kill Count",
|
||||||
"Group Kill Time",
|
"Group Kill Time",
|
||||||
"Spooned Log"
|
"Spooned Log"
|
||||||
|
|||||||
@@ -51,15 +51,9 @@ def main():
|
|||||||
# To enable the members priveleged intent:
|
# To enable the members priveleged intent:
|
||||||
# intents.members = True
|
# intents.members = True
|
||||||
|
|
||||||
# Set custom status to "Listening to ?help"
|
|
||||||
activity = nextcord.Activity(
|
|
||||||
type=nextcord.ActivityType.listening, name=f"{config.BOT_PREFIX}help"
|
|
||||||
)
|
|
||||||
|
|
||||||
bot = commands.Bot(
|
bot = commands.Bot(
|
||||||
commands.when_mentioned_or(config.BOT_PREFIX),
|
commands.when_mentioned_or(config.BOT_PREFIX),
|
||||||
intents=intents,
|
intents=intents,
|
||||||
activity=activity,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
||||||
|
|||||||
Reference in New Issue
Block a user