Browse Source

Switch to .py config

main
Ave Ozkal 2 years ago
parent
commit
74f4c11f28
No known key found for this signature in database GPG Key ID: 9356ABAA42C842B
6 changed files with 53 additions and 49 deletions
  1. +3
    -1
      .gitignore
  2. +5
    -2
      README.md
  3. +8
    -28
      Robocop.py
  4. +16
    -9
      cogs/admin.py
  5. +8
    -9
      cogs/basic.py
  6. +13
    -0
      config.py.template

+ 3
- 1
.gitignore View File

@ -97,4 +97,6 @@ files/*
.idea
*.ttf
priv-*
priv-*
config.py

+ 5
- 2
README.md View File

@ -9,10 +9,13 @@ Based on https://gitlab.com/ao/dpybotbase
## TODO
- [ ] .py configs
- [x] .py configs
- [ ] Verification
- [ ] Logging joins, leaves, role changes, deletes, bans, kicks
- [ ] Moderation commands
- [ ] Moderation commands (ban, warn etc)
- [ ] Meme commands (honestly the easiest part)
- [ ] .serr and .err
- [x] source command
- [ ] robocop command
- [ ] eval and sh might need to be removed

+ 8
- 28
Robocop.py View File

@ -3,9 +3,9 @@ import sys
import logging
import logging.handlers
import traceback
import configparser
from pathlib import Path
import aiohttp
import config
import discord
from discord.ext import commands
@ -31,12 +31,9 @@ log.setLevel(logging.INFO)
log.addHandler(file_handler)
log.addHandler(stdout_handler)
config = configparser.ConfigParser()
config.read(f"{script_name}.ini")
def get_prefix(bot, message):
prefixes = [config['base']['prefix']]
prefixes = config.prefixes
return commands.when_mentioned_or(*prefixes)(bot, message)
@ -46,7 +43,7 @@ initial_extensions = ['cogs.common',
'cogs.basic']
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.config = config
@ -69,7 +66,7 @@ async def on_ready():
log.info(f'\nLogged in as: {bot.user.name} - '
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))
@ -129,32 +126,15 @@ async def on_command_error(ctx, error):
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
async def on_message(message):
if message.author.bot:
return
if message.guild.id not in config.guild_whitelist:
return
ctx = await bot.get_context(message)
await bot.invoke(ctx)
if not Path(f"{script_name}.ini").is_file():
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)
bot.run(config.token, bot=True, reconnect=True)

+ 16
- 9
cogs/admin.py View File

@ -3,6 +3,7 @@ from discord.ext import commands
import traceback
import inspect
import re
import config
class AdminCog:
@ -11,20 +12,26 @@ class AdminCog:
self.last_eval_result = 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)
async def say(self, ctx, *, the_text: str):
"""Repeats a given text."""
await ctx.send(the_text)
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(name='exit', hidden=True)
async def _exit(self, ctx):
"""Shuts down the bot, owner only."""
await ctx.send(":wave: Exiting bot, goodbye!")
await self.bot.logout()
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def load(self, ctx, ext: str):
"""Loads a cog, owner only."""
@ -37,14 +44,14 @@ class AdminCog:
self.bot.log.info(f'Loaded ext {ext}')
await ctx.send(f':white_check_mark: `{ext}` successfully loaded.')
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def fetchlog(self, ctx):
"""Returns log"""
await ctx.send(file=discord.File(f"{self.bot.script_name}.log"),
content="Here's the current log file:")
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(name='eval', hidden=True)
async def _eval(self, ctx, *, code: str):
"""Evaluates some code (Owner only)"""
@ -97,7 +104,7 @@ class AdminCog:
for msg in sliced_message:
await ctx.send(msg)
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def pull(self, ctx, auto=False):
"""Does a git pull (Owner only)."""
@ -118,7 +125,7 @@ class AdminCog:
f'```\n{traceback.format_exc()}\n```')
return
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def sh(self, ctx, *, command: str):
"""Runs a command on shell."""
@ -138,7 +145,7 @@ class AdminCog:
for msg in sliced_message:
await ctx.send(msg)
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def unload(self, ctx, ext: str):
"""Unloads a cog, owner only."""
@ -146,7 +153,7 @@ class AdminCog:
self.bot.log.info(f'Unloaded ext {ext}')
await ctx.send(f':white_check_mark: `{ext}` successfully unloaded.')
@commands.is_owner()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def reload(self, ctx, ext="_"):
"""Reloads a cog, owner only."""


+ 8
- 9
cogs/basic.py View File

@ -1,4 +1,5 @@
import time
import config
from discord.ext import commands
@ -7,20 +8,18 @@ class Basic:
def __init__(self, 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()
async def hello(self, ctx):
"""Says hello. Duh."""
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'])
async def ping(self, ctx):
"""Shows ping values to discord.


+ 13
- 0
config.py.template View 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…
Cancel
Save