Switch to .py config
This commit is contained in:
parent
a0815b0b69
commit
74f4c11f28
6 changed files with 53 additions and 49 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -98,3 +98,5 @@ files/*
|
||||||
*.ttf
|
*.ttf
|
||||||
|
|
||||||
priv-*
|
priv-*
|
||||||
|
config.py
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,13 @@ Based on https://gitlab.com/ao/dpybotbase
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [ ] .py configs
|
- [x] .py configs
|
||||||
- [ ] Verification
|
- [ ] Verification
|
||||||
- [ ] Logging joins, leaves, role changes, deletes, bans, kicks
|
- [ ] Logging joins, leaves, role changes, deletes, bans, kicks
|
||||||
- [ ] Moderation commands
|
- [ ] Moderation commands (ban, warn etc)
|
||||||
- [ ] Meme commands (honestly the easiest part)
|
- [ ] Meme commands (honestly the easiest part)
|
||||||
- [ ] .serr and .err
|
- [ ] .serr and .err
|
||||||
|
- [x] source command
|
||||||
|
- [ ] robocop command
|
||||||
|
- [ ] eval and sh might need to be removed
|
||||||
|
|
||||||
|
|
36
Robocop.py
36
Robocop.py
|
@ -3,9 +3,9 @@ import sys
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import traceback
|
import traceback
|
||||||
import configparser
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import config
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -31,12 +31,9 @@ log.setLevel(logging.INFO)
|
||||||
log.addHandler(file_handler)
|
log.addHandler(file_handler)
|
||||||
log.addHandler(stdout_handler)
|
log.addHandler(stdout_handler)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(f"{script_name}.ini")
|
|
||||||
|
|
||||||
|
|
||||||
def get_prefix(bot, message):
|
def get_prefix(bot, message):
|
||||||
prefixes = [config['base']['prefix']]
|
prefixes = config.prefixes
|
||||||
|
|
||||||
return commands.when_mentioned_or(*prefixes)(bot, message)
|
return commands.when_mentioned_or(*prefixes)(bot, message)
|
||||||
|
|
||||||
|
@ -46,7 +43,7 @@ initial_extensions = ['cogs.common',
|
||||||
'cogs.basic']
|
'cogs.basic']
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=get_prefix,
|
bot = commands.Bot(command_prefix=get_prefix,
|
||||||
description=config['base']['description'], pm_help=None)
|
description=config.bot_description, pm_help=None)
|
||||||
|
|
||||||
bot.log = log
|
bot.log = log
|
||||||
bot.config = config
|
bot.config = config
|
||||||
|
@ -69,7 +66,7 @@ async def on_ready():
|
||||||
|
|
||||||
log.info(f'\nLogged in as: {bot.user.name} - '
|
log.info(f'\nLogged in as: {bot.user.name} - '
|
||||||
f'{bot.user.id}\ndpy version: {discord.__version__}\n')
|
f'{bot.user.id}\ndpy version: {discord.__version__}\n')
|
||||||
game_name = f"{config['base']['prefix']}help"
|
game_name = f"{config.prefixes[0]}help"
|
||||||
await bot.change_presence(activity=discord.Game(name=game_name))
|
await bot.change_presence(activity=discord.Game(name=game_name))
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,32 +126,15 @@ async def on_command_error(ctx, error):
|
||||||
f"arguments. {help_text}")
|
f"arguments. {help_text}")
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_guild_join(guild):
|
|
||||||
bot.log.info(f"Joined guild \"{guild.name}\" ({guild.id}).")
|
|
||||||
await guild.owner.send(f"Hello and welcome to {script_name}!\n"
|
|
||||||
"If you don't know why you're getting this message"
|
|
||||||
f", it's because someone added {script_name} to your"
|
|
||||||
" server\nDue to Discord API ToS, I am required to "
|
|
||||||
"inform you that **I log command usages and "
|
|
||||||
"errors**.\n**I don't log *anything* else**."
|
|
||||||
"\n\nIf you do not agree to be logged, stop"
|
|
||||||
f" using {script_name} and remove it from your "
|
|
||||||
"server as soon as possible.")
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
if message.author.bot:
|
if message.author.bot:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if message.guild.id not in config.guild_whitelist:
|
||||||
|
return
|
||||||
|
|
||||||
ctx = await bot.get_context(message)
|
ctx = await bot.get_context(message)
|
||||||
await bot.invoke(ctx)
|
await bot.invoke(ctx)
|
||||||
|
|
||||||
if not Path(f"{script_name}.ini").is_file():
|
bot.run(config.token, bot=True, reconnect=True)
|
||||||
log.warning(
|
|
||||||
f"No config file ({script_name}.ini) found, "
|
|
||||||
f"please create one from {script_name}.ini.example file.")
|
|
||||||
exit(3)
|
|
||||||
|
|
||||||
bot.run(config['base']['token'], bot=True, reconnect=True)
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from discord.ext import commands
|
||||||
import traceback
|
import traceback
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
class AdminCog:
|
class AdminCog:
|
||||||
|
@ -11,20 +12,26 @@ class AdminCog:
|
||||||
self.last_eval_result = None
|
self.last_eval_result = None
|
||||||
self.previous_eval_code = None
|
self.previous_eval_code = None
|
||||||
|
|
||||||
@commands.is_owner()
|
def check_if_staff(ctx):
|
||||||
|
return any(r.id in config.staff_role_ids for r in ctx.author.roles)
|
||||||
|
|
||||||
|
def check_if_bot_manager(ctx):
|
||||||
|
return any(r.id in config.bot_manager_role_id for r in ctx.author.roles)
|
||||||
|
|
||||||
|
@commands.check(check_if_staff)
|
||||||
@commands.command(aliases=['echo'], hidden=True)
|
@commands.command(aliases=['echo'], hidden=True)
|
||||||
async def say(self, ctx, *, the_text: str):
|
async def say(self, ctx, *, the_text: str):
|
||||||
"""Repeats a given text."""
|
"""Repeats a given text."""
|
||||||
await ctx.send(the_text)
|
await ctx.send(the_text)
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(name='exit', hidden=True)
|
@commands.command(name='exit', hidden=True)
|
||||||
async def _exit(self, ctx):
|
async def _exit(self, ctx):
|
||||||
"""Shuts down the bot, owner only."""
|
"""Shuts down the bot, owner only."""
|
||||||
await ctx.send(":wave: Exiting bot, goodbye!")
|
await ctx.send(":wave: Exiting bot, goodbye!")
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def load(self, ctx, ext: str):
|
async def load(self, ctx, ext: str):
|
||||||
"""Loads a cog, owner only."""
|
"""Loads a cog, owner only."""
|
||||||
|
@ -37,14 +44,14 @@ class AdminCog:
|
||||||
self.bot.log.info(f'Loaded ext {ext}')
|
self.bot.log.info(f'Loaded ext {ext}')
|
||||||
await ctx.send(f':white_check_mark: `{ext}` successfully loaded.')
|
await ctx.send(f':white_check_mark: `{ext}` successfully loaded.')
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def fetchlog(self, ctx):
|
async def fetchlog(self, ctx):
|
||||||
"""Returns log"""
|
"""Returns log"""
|
||||||
await ctx.send(file=discord.File(f"{self.bot.script_name}.log"),
|
await ctx.send(file=discord.File(f"{self.bot.script_name}.log"),
|
||||||
content="Here's the current log file:")
|
content="Here's the current log file:")
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(name='eval', hidden=True)
|
@commands.command(name='eval', hidden=True)
|
||||||
async def _eval(self, ctx, *, code: str):
|
async def _eval(self, ctx, *, code: str):
|
||||||
"""Evaluates some code (Owner only)"""
|
"""Evaluates some code (Owner only)"""
|
||||||
|
@ -97,7 +104,7 @@ class AdminCog:
|
||||||
for msg in sliced_message:
|
for msg in sliced_message:
|
||||||
await ctx.send(msg)
|
await ctx.send(msg)
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def pull(self, ctx, auto=False):
|
async def pull(self, ctx, auto=False):
|
||||||
"""Does a git pull (Owner only)."""
|
"""Does a git pull (Owner only)."""
|
||||||
|
@ -118,7 +125,7 @@ class AdminCog:
|
||||||
f'```\n{traceback.format_exc()}\n```')
|
f'```\n{traceback.format_exc()}\n```')
|
||||||
return
|
return
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def sh(self, ctx, *, command: str):
|
async def sh(self, ctx, *, command: str):
|
||||||
"""Runs a command on shell."""
|
"""Runs a command on shell."""
|
||||||
|
@ -138,7 +145,7 @@ class AdminCog:
|
||||||
for msg in sliced_message:
|
for msg in sliced_message:
|
||||||
await ctx.send(msg)
|
await ctx.send(msg)
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def unload(self, ctx, ext: str):
|
async def unload(self, ctx, ext: str):
|
||||||
"""Unloads a cog, owner only."""
|
"""Unloads a cog, owner only."""
|
||||||
|
@ -146,7 +153,7 @@ class AdminCog:
|
||||||
self.bot.log.info(f'Unloaded ext {ext}')
|
self.bot.log.info(f'Unloaded ext {ext}')
|
||||||
await ctx.send(f':white_check_mark: `{ext}` successfully unloaded.')
|
await ctx.send(f':white_check_mark: `{ext}` successfully unloaded.')
|
||||||
|
|
||||||
@commands.is_owner()
|
@commands.check(check_if_bot_manager)
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def reload(self, ctx, ext="_"):
|
async def reload(self, ctx, ext="_"):
|
||||||
"""Reloads a cog, owner only."""
|
"""Reloads a cog, owner only."""
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
import config
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
@ -7,20 +8,18 @@ class Basic:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command()
|
|
||||||
async def invite(self, ctx):
|
|
||||||
"""Sends an invite to add the bot"""
|
|
||||||
await ctx.send(f"{ctx.author.mention}: You can use "
|
|
||||||
"<https://discordapp.com/api/oauth2/authorize?"
|
|
||||||
f"client_id={self.bot.user.id}"
|
|
||||||
"&permissions=268435456&scope=bot> "
|
|
||||||
"to add {self.bot.user.name} to your guild.")
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def hello(self, ctx):
|
async def hello(self, ctx):
|
||||||
"""Says hello. Duh."""
|
"""Says hello. Duh."""
|
||||||
await ctx.send(f"Hello {ctx.author.mention}!")
|
await ctx.send(f"Hello {ctx.author.mention}!")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
async def source(self, ctx):
|
||||||
|
"""Gives link to source code."""
|
||||||
|
await ctx.send("You can find my source at " +
|
||||||
|
config.source_url +
|
||||||
|
". Serious PRs and issues welcome!")
|
||||||
|
|
||||||
@commands.command(aliases=['p'])
|
@commands.command(aliases=['p'])
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
"""Shows ping values to discord.
|
"""Shows ping values to discord.
|
||||||
|
|
13
config.py.template
Normal file
13
config.py.template
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Basic bot config
|
||||||
|
prefixes = [".", "!"]
|
||||||
|
token = "token-goes-here"
|
||||||
|
bot_description = "An attempt to rewrite the bot used in ReSwitched"
|
||||||
|
guild_whitelist = [
|
||||||
|
526372255052201993, # NotSwitched discord
|
||||||
|
269333940928512010 # ReSwitched discord
|
||||||
|
]
|
||||||
|
|
||||||
|
source_url = "https://github.com/aveao/robocop-ng"
|
||||||
|
|
||||||
|
bot_manager_role_id = 1
|
||||||
|
staff_role_ids = [1, 2]
|
Loading…
Reference in a new issue