adding data
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from redbot.core import commands
|
||||
from redbot.core import Config
|
||||
from random import randrange
|
||||
import discord
|
||||
from datetime import datetime
|
||||
|
||||
@@ -7,24 +9,35 @@ class ReactQuote(commands.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.config = Config.get_conf(self, identifier=8368710483)
|
||||
default_guild = {
|
||||
"quotes": []
|
||||
}
|
||||
self.config.register_guild(**default_guild)
|
||||
|
||||
def _wrapQuote(self, msg):
|
||||
return msg
|
||||
async def _addQuote(self, msg:discord.Message):
|
||||
guild_group = self.config.guild(msg.guild)
|
||||
async with guild_group.quotes() as quotes:
|
||||
quotes.append(msg)
|
||||
|
||||
def _buildQuote(self, message:discord.Message):
|
||||
|
||||
quote = f"Quoted text will be here\n[(Jump)]({message.jump_url})"
|
||||
timestamp = datetime.now()
|
||||
def _buildQuote(self, message:discord.Message, num:int):
|
||||
quote = f"{message.content}\n[(Jump)]({message.jump_url})"
|
||||
timestamp = message.created_at
|
||||
embed = discord.Embed(timestamp=timestamp)
|
||||
embed.set_author(name=message.author.display_name, icon_url=message.author.avatar_url)
|
||||
embed.add_field(name="#1", value=quote, inline=False)
|
||||
embed.add_field(name=f"#{num}", value=quote, inline=False)
|
||||
return embed
|
||||
|
||||
@commands.command()
|
||||
async def quote(self, ctx: commands.Context):
|
||||
"""Recall Random Quote"""
|
||||
# Your code will go here
|
||||
await ctx.send(embed=self._buildQuote(ctx.message))
|
||||
quotes = await self.config.guild.quotes()
|
||||
if quotes and len(quotes) > 0:
|
||||
num = randrange(len(quotes))
|
||||
await ctx.send(embed=self._buildQuote(quotes[num], num+1))
|
||||
else:
|
||||
await ctx.send("No quotes added yet. Say something funny~ OwO")
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_add(self, payload:discord.RawReactionActionEvent):
|
||||
@@ -33,4 +46,5 @@ class ReactQuote(commands.Cog):
|
||||
message: discord.Message = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id)
|
||||
user = payload.member
|
||||
channel: discord.TextChannel = message.channel
|
||||
await self._addQuote(message)
|
||||
await channel.send(f"New quote added by {user.display_name} as #1\n({message.jump_url})")
|
||||
|
||||
Reference in New Issue
Block a user