[V3 Otherbot] Initial commit

This commit is contained in:
aikaterna
2018-09-01 13:37:07 -07:00
parent fcf3a6ef2e
commit 45b1e2f83a
4 changed files with 98 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ dungeon - New users with new accounts will be shuffled off to a locked channel o
inspirobot - Fetch "inspirational" messages from inspirobot.me with [p]inspireme.
otherbot - Alert a role when bot(s) go offline.
partycrash - A port of Will's partycrash command from the v2 Admin cog. This cog will not generate invites, but will show already-existing invites that the bot has access to view.
pingtime - Show all shards' pingtimes.

5
otherbot/__init__.py Normal file
View File

@@ -0,0 +1,5 @@
from .otherbot import Otherbot
def setup(bot):
bot.add_cog(Otherbot(bot))

15
otherbot/info.json Normal file
View File

@@ -0,0 +1,15 @@
{
"author": [
"aikaterna"
],
"description": "Alerts a role when bot(s) go offline.",
"install_msg": "Thanks for installing, have fun.",
"permissions" : [
"manage_roles"
],
"short": "Alerts a role when bot(s) go offline.",
"tags": [
"bots"
],
"type": "COG"
}

76
otherbot/otherbot.py Normal file
View File

@@ -0,0 +1,76 @@
import discord
from redbot.core import commands, checks, Config
class Otherbot:
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, 2730321001, force_registration=True)
default_guild = {"ping": None, "reporting": None, "watching": []}
self.config.register_guild(**default_guild)
@commands.group()
@commands.guild_only()
@checks.admin_or_permissions(manage_roles=True)
async def otherbot(self, ctx):
"""Otherbot configuration options."""
pass
@otherbot.command()
async def channel(self, ctx, channel: discord.TextChannel = None):
"""Sets the channel to report in."""
await self.config.guild(ctx.guild).reporting.set(channel.id)
await ctx.send(f"Reporting channel set to: {channel.mention}.")
@otherbot.command()
async def pingrole(self, ctx, role_name: discord.Role = None):
"""Sets the role to use for pinging. Leave blank to reset it."""
if not role_name:
await self.config.guild(ctx.guild).ping()
return await ctx.send("Ping role cleared.")
await self.config.guild(ctx.guild).ping.set(role_name.id)
pingrole_id = await self.config.guild(ctx.guild).ping()
pingrole_obj = discord.utils.get(ctx.guild.roles, id=pingrole_id)
await ctx.send(f"Ping role set to: {pingrole_obj.name}.")
@otherbot.command()
@checks.admin_or_permissions(manage_roles=True)
async def watching(self, ctx, bot_user: discord.Member = None):
"""Add a bot to watch. Leave blank to list existing bots on the list."""
data = await self.config.guild(ctx.guild).all()
msg = "```Watching these bots:\n"
if not data["watching"]:
msg += "None.```"
if not bot_user:
for saved_bot_id in data["watching"]:
bot_user = await self.bot.get_user_info(saved_bot_id)
if len(bot_user.name) > 16:
bot_name = f"{bot_user.name:16}...#{bot_user.discriminator}"
else:
bot_name = f"{bot_user.name}#{bot_user.discriminator}"
msg += f"{bot_name:24} ({bot_user.id})\n"
msg += "```"
return await ctx.send(msg)
if not bot_user.bot:
return await ctx.send("User is not a bot.")
async with self.config.guild(ctx.guild).watching() as watch_list:
watch_list.append(bot_user.id)
await ctx.send(f"Now watching: {bot_user.mention}.")
if not data["reporting"]:
await self.config.guild(ctx.guild).reporting.set(ctx.message.channel.id)
await ctx.send(
f"Reporting channel set to: {ctx.message.channel.mention}. Use `{ctx.prefix}otherbot channel` to change this."
)
async def on_member_update(self, before, after):
data = await self.config.guild(after.guild).all()
if after.status == discord.Status.offline and (after.id in data["watching"]):
channel_object = self.bot.get_channel(data["reporting"])
if not data["ping"]:
await channel_object.send(f'{after.mention} is offline.')
else:
await channel_object.send(f'<@&{data["ping"]}>, {after.mention} is offline.')
else:
pass