mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
utilise redis ping
This commit is contained in:
parent
cd45dc4844
commit
87510bd73a
1 changed files with 13 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
import textwrap
|
import textwrap
|
||||||
import redis
|
import redis
|
||||||
import json
|
import json
|
||||||
|
@ -13,6 +14,7 @@ from discord.ext import commands
|
||||||
class StarBoardCog(commands.Cog):
|
class StarBoardCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.log = logging.getLogger("jimmy.starboard")
|
||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
self.redis = redis.asyncio.Redis(decode_responses=True)
|
self.redis = redis.asyncio.Redis(decode_responses=True)
|
||||||
|
|
||||||
|
@ -48,6 +50,9 @@ class StarBoardCog(commands.Cog):
|
||||||
embeds = [embed, *starboard_message.embeds[1:]]
|
embeds = [embed, *starboard_message.embeds[1:]]
|
||||||
await starboard_message.edit(embeds=embeds, file=discord.File(file, filename=filename))
|
await starboard_message.edit(embeds=embeds, file=discord.File(file, filename=filename))
|
||||||
|
|
||||||
|
async def _ping_check(self):
|
||||||
|
return await self.redis.ping()
|
||||||
|
|
||||||
async def generate_starboard_embed(self, message: discord.Message) -> discord.Embed:
|
async def generate_starboard_embed(self, message: discord.Message) -> discord.Embed:
|
||||||
star_count = [x for x in message.reactions if str(x.emoji) == "\N{white medium star}"]
|
star_count = [x for x in message.reactions if str(x.emoji) == "\N{white medium star}"]
|
||||||
if not star_count:
|
if not star_count:
|
||||||
|
@ -126,6 +131,9 @@ class StarBoardCog(commands.Cog):
|
||||||
async def on_star_add(self, payload: discord.RawReactionActionEvent):
|
async def on_star_add(self, payload: discord.RawReactionActionEvent):
|
||||||
if not payload.guild_id:
|
if not payload.guild_id:
|
||||||
return
|
return
|
||||||
|
if not await self._ping_check():
|
||||||
|
self.log.warning("Redis ping check failed - redis offline?")
|
||||||
|
return
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
if str(payload.emoji) != "\N{white medium star}":
|
if str(payload.emoji) != "\N{white medium star}":
|
||||||
return
|
return
|
||||||
|
@ -219,6 +227,10 @@ class StarBoardCog(commands.Cog):
|
||||||
@commands.message_command(name="Starboard Info")
|
@commands.message_command(name="Starboard Info")
|
||||||
@discord.guild_only()
|
@discord.guild_only()
|
||||||
async def get_starboard_info(self, ctx: discord.ApplicationContext, message: discord.Message):
|
async def get_starboard_info(self, ctx: discord.ApplicationContext, message: discord.Message):
|
||||||
|
if not await self._ping_check():
|
||||||
|
self.log.warning("Redis ping check failed - redis offline?")
|
||||||
|
data = {"warning": "redis offline - ping failed."}
|
||||||
|
else:
|
||||||
data = await self.redis.get(str(message.id))
|
data = await self.redis.get(str(message.id))
|
||||||
return await ctx.respond(
|
return await ctx.respond(
|
||||||
'```json\n%s\n```' % json.dumps(data, indent=4),
|
'```json\n%s\n```' % json.dumps(data, indent=4),
|
||||||
|
|
Loading…
Reference in a new issue