Manually add quotes
This commit is contained in:
@@ -34,13 +34,43 @@ class ReactQuote(commands.Cog):
|
|||||||
await guild_group.quotes.set(quotes)
|
await guild_group.quotes.set(quotes)
|
||||||
return len(quotes)
|
return len(quotes)
|
||||||
|
|
||||||
|
async def _manualAddQuote(self, guild, author, message):
|
||||||
|
formattedMsg = {
|
||||||
|
"messageText": message,
|
||||||
|
"authorId": author.id
|
||||||
|
}
|
||||||
|
guild_group = self.config.guild(guild)
|
||||||
|
quotes = await guild_group.quotes()
|
||||||
|
if quotes.count(formattedMsg) > 0:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
quotes.append(formattedMsg)
|
||||||
|
await guild_group.quotes.set(quotes)
|
||||||
|
return len(quotes)
|
||||||
|
|
||||||
async def _removeQuote(self, guild: discord.Guild, n:int):
|
async def _removeQuote(self, guild: discord.Guild, n:int):
|
||||||
guild_group = self.config.guild(guild)
|
guild_group = self.config.guild(guild)
|
||||||
quotes = await guild_group.quotes()
|
quotes = await guild_group.quotes()
|
||||||
quotes.pop(n)
|
quotes.pop(n)
|
||||||
await guild_group.quotes.set(quotes)
|
await guild_group.quotes.set(quotes)
|
||||||
|
|
||||||
def _buildQuote(self, message, num:int):
|
async def _buildQuote(self, ctx:commands.Context, formattedMessage, num:int):
|
||||||
|
if formattedMessage["messageId"] is not None:
|
||||||
|
message = await ctx.guild.get_channel(formattedMessage['channelId']).fetch_message(formattedMessage['messageId'])
|
||||||
|
quote = f"{message.content}\n[(Jump)]({message.jump_url})"
|
||||||
|
timestamp = message.created_at
|
||||||
|
author = message.author
|
||||||
|
else:
|
||||||
|
message = formattedMessage["messageText"]
|
||||||
|
quote = f"{message}\n*Added Manually*"
|
||||||
|
timestamp = ctx.message.created_at
|
||||||
|
author = ctx.guild.get_member(formattedMessage["authorId"])
|
||||||
|
embed = discord.Embed(timestamp=timestamp)
|
||||||
|
embed.set_author(name=author.display_name, icon_url=author.avatar_url)
|
||||||
|
embed.add_field(name=f"#{num}", value=quote, inline=False)
|
||||||
|
return embed
|
||||||
|
|
||||||
|
def _oldBuildQuote(self, message, num:int):
|
||||||
quote = f"{message.content}\n[(Jump)]({message.jump_url})"
|
quote = f"{message.content}\n[(Jump)]({message.jump_url})"
|
||||||
timestamp = message.created_at
|
timestamp = message.created_at
|
||||||
embed = discord.Embed(timestamp=timestamp)
|
embed = discord.Embed(timestamp=timestamp)
|
||||||
@@ -57,21 +87,20 @@ class ReactQuote(commands.Cog):
|
|||||||
'quote' returns random
|
'quote' returns random
|
||||||
'quote 3' returns the #3 quote
|
'quote 3' returns the #3 quote
|
||||||
"""
|
"""
|
||||||
# Your code will go here
|
|
||||||
quotes = await self.config.guild(ctx.guild).quotes()
|
quotes = await self.config.guild(ctx.guild).quotes()
|
||||||
numQuotes = len(quotes)
|
numQuotes = len(quotes)
|
||||||
if numQuotes > 0:
|
if numQuotes > 0:
|
||||||
if(query == ""):
|
if(query == ""):
|
||||||
"""case random"""
|
"""case random"""
|
||||||
num = randrange(len(quotes))
|
num = randrange(len(quotes))
|
||||||
message = await ctx.guild.get_channel(quotes[num]['channelId']).fetch_message(quotes[num]['messageId'])
|
embed = await self._buildQuote(ctx, quotes[num], num+1)
|
||||||
await ctx.send(embed=self._buildQuote(message, num+1))
|
await ctx.send(embed=embed)
|
||||||
elif(re.search("^\d+$", query) is not None):
|
elif(re.search("^\d+$", query) is not None):
|
||||||
"""case id"""
|
"""case id"""
|
||||||
num = int(query)
|
num = int(query)
|
||||||
if num <= numQuotes:
|
if num <= numQuotes:
|
||||||
message = await ctx.guild.get_channel(quotes[num-1]['channelId']).fetch_message(quotes[num-1]['messageId'])
|
embed = await self._buildQuote(ctx, quotes[num], num+1)
|
||||||
await ctx.send(embed=self._buildQuote(message, num))
|
await ctx.send(embed=embed)
|
||||||
else:
|
else:
|
||||||
await ctx.send(f"There are only {numQuotes} quotes")
|
await ctx.send(f"There are only {numQuotes} quotes")
|
||||||
elif(len(ctx.message.mentions) > 0):
|
elif(len(ctx.message.mentions) > 0):
|
||||||
@@ -89,8 +118,8 @@ class ReactQuote(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
num = randrange(len(filteredQuotes))
|
num = randrange(len(filteredQuotes))
|
||||||
globalNum = quotes.index(filteredQuotes[num])
|
globalNum = quotes.index(filteredQuotes[num])
|
||||||
message = await ctx.guild.get_channel(filteredQuotes[num]['channelId']).fetch_message(filteredQuotes[num]['messageId'])
|
embed = await self._buildQuote(ctx, filteredQuotes[num], globalNum+1)
|
||||||
await ctx.send(embed=self._buildQuote(message, globalNum+1))
|
await ctx.send(embed=embed)
|
||||||
else:
|
else:
|
||||||
"""Testing case"""
|
"""Testing case"""
|
||||||
await ctx.send(f"{query} was not picked up. (This is for testing purposes)")
|
await ctx.send(f"{query} was not picked up. (This is for testing purposes)")
|
||||||
@@ -98,6 +127,35 @@ class ReactQuote(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
await ctx.send("No quotes added yet.\nSay something funny~ OwO")
|
await ctx.send("No quotes added yet.\nSay something funny~ OwO")
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.command()
|
||||||
|
async def addquote(self, ctx: commands.Context, *, query: str):
|
||||||
|
"""Manually add quote. @ the speaker of quote to properly credit them"""
|
||||||
|
if query is None or len(query) == 0:
|
||||||
|
await ctx.send("No quote provided. What are you saying? OwO")
|
||||||
|
else:
|
||||||
|
quotes = await self.config.guild(ctx.guild).quotes()
|
||||||
|
numQuotes = len(quotes)
|
||||||
|
quote = f"{query}\n*Added Manually*)"
|
||||||
|
timestamp = ctx.message.created_at
|
||||||
|
embed = discord.Embed(timestamp=timestamp)
|
||||||
|
if len(ctx.message.mentions) > 0:
|
||||||
|
member: discord.Member = ctx.message.mentions[0]
|
||||||
|
self._manualAddQuote(self, ctx.guild, member, quote)
|
||||||
|
await ctx.send(f"New quote manually added by {ctx.author.display_name} as #{numQuotes}")
|
||||||
|
guild_group = self.config.guild(ctx.guild)
|
||||||
|
settings = await guild_group.reactQuotesSettings()
|
||||||
|
if settings["outputChannel"] is not None:
|
||||||
|
logChan = ctx.guild.get_channel(settings["outputChannel"])
|
||||||
|
formattedMsg = {
|
||||||
|
"messageText": quote,
|
||||||
|
"authorId": member.id
|
||||||
|
}
|
||||||
|
embed = await self._buildQuote(ctx, formattedMsg, numQuotes)
|
||||||
|
await logChan.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@commands.admin_or_permissions(manage_guild=True)
|
@commands.admin_or_permissions(manage_guild=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@@ -125,8 +183,8 @@ class ReactQuote(commands.Cog):
|
|||||||
"""Print all quotes"""
|
"""Print all quotes"""
|
||||||
quotes = await self.config.guild(ctx.guild).quotes()
|
quotes = await self.config.guild(ctx.guild).quotes()
|
||||||
for index, quote in enumerate(quotes):
|
for index, quote in enumerate(quotes):
|
||||||
message = await ctx.guild.get_channel(quote['channelId']).fetch_message(quote['messageId'])
|
embed = await self._buildQuote(ctx, quote, index+1)
|
||||||
await ctx.send(embed=self._buildQuote(message, index+1))
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -144,6 +202,6 @@ class ReactQuote(commands.Cog):
|
|||||||
settings = await guild_group.reactQuotesSettings()
|
settings = await guild_group.reactQuotesSettings()
|
||||||
if settings["outputChannel"] is not None:
|
if settings["outputChannel"] is not None:
|
||||||
logChan = message.guild.get_channel(settings["outputChannel"])
|
logChan = message.guild.get_channel(settings["outputChannel"])
|
||||||
await logChan.send(embed=self._buildQuote(message, pos))
|
await logChan.send(embed=self._oldBuildQuote(message, pos))
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user