Skip to content

Commit

Permalink
Beginning framework
Browse files Browse the repository at this point in the history
  • Loading branch information
freiheit committed Oct 29, 2023
1 parent 6e6bcd3 commit f6c8318
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mvkdicebot.example.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[MAIN]
# Follow instructions here to get token:
# https://discord.com/developers/docs/getting-started
authtoken = abc1234

# Bot invite:
# https://discord.com/api/oauth2/authorize?client_id=1168083075515826186&permissions=277025442816&scope=bot
# (replace client_id with your bot acct client_id)

# debug levels:
# 0 -> startup and errors only
# 1 -> small amounts of info
# 2 -> detailed
# 3 -> too much details?
debug = 0
83 changes: 83 additions & 0 deletions mvkdicebot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
# MvKDiceBot: Discord bot for rolling dice for Mecha Vs Kaiju
# Copyright (C) 2023 Eric Eisenhart
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# https://github.com/freiheit/MvKDiceBot

import asyncio
import discord
import logging
import random

from configparser import ConfigParser
from discord.ext import commands

__version__ = "0.0.1"
description = '''A dice rolling bot for MvK
'''

intents = discord.Intents.default()

bot = commands.Bot(command_prefix='?', description=description, intents=intents)

DEFAULT_CONFIG_PATHS = [
os.path.join(HOME_DIR, ".mvkdicebot.ini"),
os.path.join("/etc/mvkdicebot.ini"),
os.path.join(BASE_DIR, "mvkdicebot.ini"),
os.path.join("mvkdicebot.ini"),
]

def get_config():
config = ConfigParser()
config_paths = []

if args.config:
config_paths = [args.config]
else:
for path in DEFAULT_CONFIG_PATHS:
if os.path.isfile(path):
config_paths.append(path)
break
else:
raise ImproperlyConfigured("No configuration file found.")

for path in DEFAULT_AUTH_CONFIG_PATHS:
if os.path.isfile(path):
config_paths.append(path)
break

config.read(config_paths)

debug = config["MAIN"].getint("debug", 0)

if debug >= 3:
log_level = logging.DEBUG
elif debug >= 2:
log_level = logging.INFO
elif debug >= 1:
log_level = logging.WARNING
else:
log_level = logging.ERROR

logging.basicConfig(level=log_level)
logger = logging.getLogger(__name__)
logger.setLevel(log_level)
warnings.resetwarnings()

return config, logger

config, logger = get_config()

0 comments on commit f6c8318

Please sign in to comment.