Skip to content

Commit

Permalink
keepalive plugin v2.0.0:
Browse files Browse the repository at this point in the history
- Remove internal support for UptimeRobot. Users now have to set it manually using dashboard on UptimeRobots website.
  • Loading branch information
Jerrie-Aries committed Feb 2, 2024
1 parent 899dfa6 commit a5eeb66
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 224 deletions.
176 changes: 0 additions & 176 deletions keepalive/core/clients.py

This file was deleted.

2 changes: 1 addition & 1 deletion keepalive/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"wiki": "https://github.com/Jerrie-Aries/modmail-plugins/wiki/Keep-Alive-plugin-guide",
"authors": ["Jerrie-Aries"],
"version": "1.0.1",
"version": "2.0.0",
"bot_version": "4.0.0",
"dpy_version": "2.0.0"
}
48 changes: 1 addition & 47 deletions keepalive/keepalive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from discord.ext import commands

from core import checks
from core.models import getLogger, PermissionLevel
from core.models import PermissionLevel

from .core.clients import UptimeRobotAPIClient
from .core.servers import KeepAliveServer


Expand All @@ -27,8 +26,6 @@
__version__ = __plugin_info__["version"]
__description__ = "\n".join(__plugin_info__["description"]).format(__plugin_info__["wiki"], __version__)

logger = getLogger(__name__)


class KeepAlive(commands.Cog, name=__plugin_name__):
__doc__ = __description__
Expand All @@ -42,7 +39,6 @@ def __init__(self, bot: ModmailBot):
"""
self.bot: ModmailBot = bot
self.keep_alive: Optional[KeepAliveServer] = None
self.uptimerobot_client: Optional[UptimeRobotAPIClient] = None
self.repl_slug: Optional[str] = os.environ.get("REPL_SLUG")
self.repl_owner: Optional[str] = os.environ.get("REPL_OWNER")
self.using_replit: bool = self.repl_slug is not None
Expand All @@ -52,13 +48,6 @@ async def cog_load(self) -> None:
self.keep_alive = KeepAliveServer(self.repl_slug, self.repl_owner)
await self.keep_alive.start()

api_key = os.environ.get("UPTIMEROBOT_API_KEY")
if api_key:
self.uptimerobot_client = UptimeRobotAPIClient(self, api_key=api_key)
await self.uptimerobot_client.check_monitor()
else:
logger.error("UPTIMEROBOT_API_KEY is not set.")

async def cog_unload(self) -> None:
await self._shutdown_keep_alive()

Expand Down Expand Up @@ -126,41 +115,6 @@ async def keepalive_info(self, ctx: commands.Context):
embed.set_footer(text=f"Version: v{__version__}")
await ctx.send(embed=embed)

@commands.group(name="uptimerobot", aliases=["uprob"], invoke_without_command=True)
@checks.has_permissions(PermissionLevel.OWNER)
async def uptimerobot_group(self, ctx: commands.Context):
"""
UptimeRobot tools.
"""
await ctx.send_help(ctx.command)

@uptimerobot_group.command(name="info")
@checks.has_permissions(PermissionLevel.OWNER)
async def uptimerobot_info(self, ctx: commands.Context, option: Optional[str] = None):
"""
Shows the UptimeRobot monitor information.
`option` can be `refresh` or `fetch`, this will fetch the latest monitor information from API.
"""
if self.uptimerobot_client is None:
raise commands.BadArgument("UptimeRobot service is not set due to missing API key.")
monitor = self.uptimerobot_client.monitor
if monitor is None:
raise commands.BadArgument("UptimeRobot monitor is not set.")

if option and option.lower() in ("fetch", "refresh"):
await monitor.refresh()

embed = discord.Embed(title="UptimeRobot", color=self.bot.main_color)
embed.add_field(name="ID", value=str(monitor.id))
embed.add_field(name="Name", value=monitor.friendly_name)
embed.add_field(name="URL", value=monitor.url)
embed.add_field(name="Type", value=monitor.type)
embed.add_field(name="Interval", value=str(monitor.interval))
embed.add_field(name="Status", value=monitor.status)

await ctx.send(embed=embed)


async def setup(bot: ModmailBot) -> None:
await bot.add_cog(KeepAlive(bot))

0 comments on commit a5eeb66

Please sign in to comment.