Browse Source

added logging to roxbot.

tags/v1.5.0
Roxie Gibson 6 years ago
parent
commit
3170c13f97
5 changed files with 87 additions and 9 deletions
  1. +13
    -7
      Roxbot/cogs/fun.py
  2. +40
    -0
      Roxbot/logging.py
  3. +7
    -2
      Roxbot/settings/guild_settings.py
  4. +26
    -0
      Roxbot/settings/settings.py
  5. +1
    -0
      main.py

+ 13
- 7
Roxbot/cogs/fun.py View File

@@ -1,9 +1,13 @@
import discord
import random
from Roxbot import checks
import discord
import requests
from discord.ext.commands import bot

from Roxbot import checks
from Roxbot.settings import guild_settings
from Roxbot.logging import Logging



class Fun:
def __init__(self, bot_client):
@@ -125,14 +129,16 @@ class Fun:
return await ctx.send("The coin landed on {}!".format(random.choice(["heads", "tails"])))

@bot.command()
async def aesthetics(self, ctx, *convert):
async def aesthetics(self, ctx, *, convert):
"""Converts text to be more a e s t h e t i c s"""
WIDE_MAP = dict((i, i + 0xFEE0) for i in range(0x21, 0x7F))
WIDE_MAP[0x20] = 0x3000
convert = str(' '.join(convert)).translate(WIDE_MAP)
if ctx.guild.id == 393764974444675073:
await self.bot.get_channel(394959819796381697).send("{} used the aesthetics command passing the argument '{}'".format(str(ctx.author), ' '.join(convert)))
return await ctx.send(convert)
converted = str(convert).translate(WIDE_MAP)

logging = guild_settings.get(ctx.guild).logging
if logging["enabled"]:
await Logging(self.bot).log(ctx.guild, "aesthetics", user=ctx.author, argument_given=convert)
return await ctx.send(converted)

@bot.command(aliases=["ft", "frog"])
async def frogtips(self, ctx):

+ 40
- 0
Roxbot/logging.py View File

@@ -0,0 +1,40 @@
import discord
from discord.ext.commands import bot
from Roxbot.settings import guild_settings
from Roxbot.load_config import embedcolour

class Logging:
def __init__(self, bot_client):
self.bot = bot_client

async def on_member_join(self, member):
logging = guild_settings.get(member.guild).logging
if logging["enabled"]:
channel = self.bot.get_channel(logging["channel"])
embed = discord.Embed(title="{} joined the server".format(member), colour=embedcolour)
embed.add_field(name="ID", value=member.id)
embed.add_field(name="Mention", value=member.mention)
embed.add_field(name="Date Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at))
embed.add_field(name="Date Joined", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.joined_at))
embed.set_thumbnail(url=member.avatar_url)
return await channel.send(embed=embed)

async def on_member_remove(self, member):
# TODO: Add some way of detecting whether a user left/was kicked or was banned.
logging = guild_settings.get(member.guild).logging
if logging["enabled"]:
channel = self.bot.get_channel(logging["channel"])
embed = discord.Embed(description="{} left the server".format(member), colour=embedcolour)
return await channel.send(embed=embed)

async def log(self, guild, command_name, **kwargs):
logging = guild_settings.get(guild).logging
if logging["enabled"]:
channel = self.bot.get_channel(logging["channel"])
embed=discord.Embed(title="{} command logging".format(command_name), colour=embedcolour)
for key, value in kwargs.items():
embed.add_field(name=key, value=value)
return await channel.send(embed=embed)

def setup(bot_client):
bot_client.add_cog(Logging(bot_client))

+ 7
- 2
Roxbot/settings/guild_settings.py View File

@@ -44,7 +44,11 @@ guild_template = {
"required_score": "",
},
"warnings": {},
"is_anal": {"y/n": 0}
"is_anal": {"y/n": 0},
"logging": {
"enabled": 0,
"channel": 0
}
}
}

@@ -132,7 +136,7 @@ class GuildSettings(object):
An Object to store all settings for one guild.
The goal is to make editing settings a lot easier and make it so you don't have to handle things like ID's which caused a lot of issues when moving over to discord.py 1.0
"""
__slots__ = ["settings", "id", "name", "nsfw", "self_assign", "greets", "goodbyes", "twitch", "perm_roles", "custom_commands", "warnings", "is_anal", "gss"]
__slots__ = ["settings", "id", "name", "logging", "nsfw", "self_assign", "greets", "goodbyes", "twitch", "perm_roles", "custom_commands", "warnings", "is_anal", "gss"]

def __init__(self, guild):
self.id = guild.id
@@ -147,6 +151,7 @@ class GuildSettings(object):
return _open_config()[str(self.id)]

def get_settings(self):
self.logging = self.settings["logging"]
self.nsfw = self.settings["nsfw"]
self.self_assign = self.settings["self_assign"]
self.greets = self.settings["greets"]

+ 26
- 0
Roxbot/settings/settings.py View File

@@ -186,6 +186,32 @@ class Settings:
return await ctx.send('Missing Argument')
self.guild_settings = guild_settings.get(ctx.guild)

@settings.command(aliases=["log"])
async def logging(self, ctx, selection, *, changes = None):
"""Edits the logging settings.

Options:
enable/disable: Enable/disables logging.
channel: sets the channel.
"""
selection = selection.lower()
settings = guild_settings.get(ctx.guild)

if selection == "enable":
settings.logging["enabled"] = 1
await ctx.send("'logging' was enabled!")
elif selection == "disable":
settings.logging["enabled"] = 0
await ctx.send("'logging' was disabled :cry:")
elif selection == "channel":
channel = self.get_channel(ctx, changes)
settings.logging["channel"] = channel.id
await ctx.send("{} has been set as the logging channel!".format(channel.mention))
else:
return await ctx.send("No valid option given.")
return self.guild_settings.update(settings.logging, "logging")


@settings.command(aliases=["sa"])
async def selfassign(self, ctx, selection, *, changes = None):
"""Edits settings for self assign cog.

+ 1
- 0
main.py View File

@@ -114,4 +114,5 @@ if __name__ == "__main__":
start_time = time.time()
bot.load_extension("Roxbot.settings.settings")
bot.load_extension("Roxbot.err_handle")
bot.load_extension("Roxbot.logging")
bot.run(load_config.token)

Loading…
Cancel
Save