Skip to content

Commit

Permalink
Merge pull request #26 from organic-bots/config
Browse files Browse the repository at this point in the history
Multi-server configuration
  • Loading branch information
s0lst1ce committed Jun 28, 2019
2 parents d142503 + 25ec293 commit bb056a7
Show file tree
Hide file tree
Showing 14 changed files with 1,500 additions and 588 deletions.
42 changes: 27 additions & 15 deletions BotEssentials.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from settings import *
import discord
from checks import *

from utilities import *
import json


#########################################
Expand Down Expand Up @@ -34,6 +34,14 @@ class BotEssentials(commands.Cog):
"""All of the essential methods all of our bots should have"""
def __init__(self, bot):
self.bot = bot


@commands.Cog.listener()
async def on_guild_join(self, guild):
with open(f"{guild.id}.json", "w") as file:
file.write(DEFAULT_SERVER_FILE)
local_logger.info(f"Joined server {guild.name}")


@commands.Cog.listener()
async def on_ready(self):
Expand All @@ -42,21 +50,23 @@ async def on_ready(self):
@commands.Cog.listener()
async def on_member_join(self, member):
local_logger.info("User {0.name}[{0.id}] joined {1.name}[{1.id}]".format(member, member.guild))
await member.guild.system_channel.send("Welcome to {} {}! Please make sure to take a look at our {} and before asking a question, at the {}".format(member.guild.name, member.mention, CHANNELS["rules"].mention, CHANNELS["faq"].mention))
welcome_msg = get_conf(member.guild.id)["messages"]["welcome"]
if welcome_msg != False:
await member.guild.system_channel.send(welcome_msg.format(member.mention))

@commands.Cog.listener()
async def on_member_remove(self, member):
local_logger.info("User {0.name}[{0.id}] left {1.name}[{1.id}]".format(member, member.guild))
await member.guilg.system_channel.send("Goodbye {0.name} {1}, may your wandering be fun!".format(member, EMOJIS["wave"]))

goodbye_msg = get_conf(member.guild.id)["messages"]["goodbye"]
if goodbye_msg != False:
await member.guild.system_channel.send(goodbye_msg.format(member.mention))

@commands.command()
async def ping(self, ctx):
'''This command responds with the current latency.'''
latency = self.bot.latency
await ctx.send("**Pong !** Latency of {0:.3f} seconds".format(latency))


#Command that shuts down the bot
@commands.command()
@is_runner()
Expand All @@ -72,17 +82,19 @@ async def shutdown(self, ctx):
await quit()

@commands.command()
@commands.has_any_role(*GESTION_ROLES)
async def clear(slef, ctx, nbr:int):
@has_auth("manager")
async def clear(self, ctx, nbr:int):
'''deletes specified <nbr> number of messages in the current channel'''
async for msg in ctx.channel.history(limit=nbr):
to_del = []
async for msg in ctx.channel.history(limit=nbr+1):
local_logger.info("Deleting {}".format(msg))
try:
await msg.delete()
except Exception as e:
local_logger.exception("Couldn't delete {}".format(msg))
raise e

to_del.append(msg)

try:
await ctx.channel.delete_messages(to_del)
except Exception as e:
local_logger.exception("Couldn't delete at least on of{}".format(to_del))
raise e



Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ Although contributing to the project is allowed and even encouraged it has to fo



This is a *guideline* which means that some exceptions may be made. However it is recommend that you respect it for your contribution to be validated. If you have any other question or think a point is unclear or too limiting feel free to contact an @admin

This is a *guideline* which means that some exceptions may be made. However it is recommend that you respect it for your contribution to be validated. If you have any other question or think a point is unclear or too limiting feel free to contact an @admin

0 comments on commit bb056a7

Please sign in to comment.