Browse Source

Moved settings files to folder and added configparser for the tokens and other settings.

tags/v0.3.0
roxie 7 years ago
parent
commit
0f963a4e56
4 changed files with 79 additions and 21 deletions
  1. +0
    -0
      config/blacklist.txt
  2. +0
    -0
      config/config.json
  3. +7
    -0
      config/settings.ini
  4. +72
    -21
      main.py

blacklist.txt → config/blacklist.txt View File


config.json → config/config.json View File


+ 7
- 0
config/settings.ini View File

[Credentials]
; Put your token here.
Token =

[RoxBot]
OwnerID = 142735312626515979
CommandPrefix = "."

+ 72
- 21
main.py View File

# RoxBot
# Version = 1.1
# Author = Roxxers

############## ##############
# To-do List # # To-do List #
############## ##############


# High Priority #
# TODO: Command Review, look at all commands and flesh them out. Maybe some randomised dialogue so that not every command has only one response. Also self delete timers. Make sure user experience feels nice.
# TODO: Complete rework of the commands. Moving to cog based commands again. Rework the code to be easier and cleaner.

# Mid Priority #
# TODO: Move away from using ID's for everthing. Maybe replace list with dict
# TODO: Admin tools - For commands already in and things like purge a chat
# TODO: On member role assign, welcome member using on_member_update # TODO: On member role assign, welcome member using on_member_update

# Low Priority #
# TODO: Better help menu- AutoGen using <command>.help # TODO: Better help menu- AutoGen using <command>.help
# TODO: WaifuRater - Mention user and RNG a rating
# TODO: Admin tools - For commands already in and things like purge a chat
# TODO: Overwatch stats - Using Overwatch-API lib # TODO: Overwatch stats - Using Overwatch-API lib
# TODO: Move away from using ID's for everthing. Maybe replace list with dict
# TODO: Add check for no channel id when a module is enabled
# TODO: Add check for no channel id when a module is enabled




import json import json
import random import random
import os
import sys
import configparser


import discord import discord
from discord.ext.commands import Bot from discord.ext.commands import Bot


bot = Bot(command_prefix=".")
# bot.remove_command("help")
# TODO: Take these from a file, not the program
token = 'MzA4MDc3ODg3MDYyNTQwMjg5.DEW5YA.JfLfU5jPjTFQi0xFI6B_-SKvC54'
owner_id = "142735312626515979"

__version__ = '0.3.0'


settings = configparser.ConfigParser()
settings.read('config/settings.ini')

token = settings["Credentials"]["Token"]
owner_id = settings["RoxBot"]["OwnerID"]
command_prefix = settings["RoxBot"]["CommandPrefix"]

bot = Bot(command_prefix=command_prefix)



config_template = { config_template = {
"example": { "example": {




def load_config(): def load_config():
with open('config.json', 'r') as config_file:
with open('config/config.json', 'r') as config_file:
return json.load(config_file) return json.load(config_file)




def updateconfig(): def updateconfig():
with open('config.json', 'w') as conf_file:
with open('config/config.json', 'w') as conf_file:
json.dump(config, conf_file) json.dump(config, conf_file)








def blacklisted(user): def blacklisted(user):
with open("blacklist.txt", "r") as fp:
with open("config/blacklist.txt", "r") as fp:
for line in fp.readlines(): for line in fp.readlines():
if user.id+"\n" == line: if user.id+"\n" == line:
return True return True
async def on_ready(): async def on_ready():
# TODO: First part needs to be moved to wait_until_ready # TODO: First part needs to be moved to wait_until_ready
config_errorcheck() config_errorcheck()

await bot.change_presence(game=discord.Game(name="v1.2_Testing"), status=discord.Status.dnd, afk=False)
print(discord.__version__)
print("Client logged in\n") print("Client logged in\n")
print("Servers I am currently in:") print("Servers I am currently in:")
for server in bot.servers: for server in bot.servers:
return await bot.say(roles) return await bot.say(roles)




@bot.command(pass_context=True)
async def waifurate(ctx):
mentions = ctx.message.mentions
if not mentions:
return await bot.reply("You didn't mention anyone for me to rate.", delete_after=10)

rating = random.randrange(1, 11)
if rating <= 2:
emoji = ":sob:"
elif rating <= 4:
emoji = ":disappointed:"
elif rating <= 6:
emoji = ":thinking:"
elif rating <= 8:
emoji = ":blush:"
elif rating == 9:
emoji = ":kissing_heart:"
else:
emoji = ":heart_eyes:"

if len(mentions) > 1:
return await bot.say("Oh poly waifu rating? :smirk: Your combined waifu rating is {}/10. {}".format(rating, emoji))
else:
return await bot.say("Oh that's your waifu? I rate them a {}/10. {}".format(rating, emoji))


################## ##################
# Owner Commands # # Owner Commands #
################## ##################
mentions.remove(user) mentions.remove(user)


if option in ['+', 'add']: if option in ['+', 'add']:
with open("blacklist.txt", "r") as fp:
with open("config/blacklist.txt", "r") as fp:
for user in mentions: for user in mentions:
for line in fp.readlines(): for line in fp.readlines():
if user.id+"\n" in line: if user.id+"\n" in line:
mentions.remove(user) mentions.remove(user)


with open("blacklist.txt","a+") as fp:
with open("config/blacklist.txt","a+") as fp:
lines = fp.readlines() lines = fp.readlines()
for user in mentions: for user in mentions:
if user.id not in lines: if user.id not in lines:
return await bot.say('{} user(s) have been added to the blacklist'.format(blacklist_amount)) return await bot.say('{} user(s) have been added to the blacklist'.format(blacklist_amount))


elif option in ['-', 'remove']: elif option in ['-', 'remove']:
with open("blacklist.txt","r") as fp:
with open("config/blacklist.txt","r") as fp:
lines = fp.readlines() lines = fp.readlines()
with open("blacklist.txt","w") as fp:
with open("config/blacklist.txt","w") as fp:
for user in mentions: for user in mentions:
for line in lines: for line in lines:
if user.id+"\n" != line: if user.id+"\n" != line:
return await bot.say(config[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"]) return await bot.say(config[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"])




@bot.command()
async def restart():
await bot.logout()
return os.execl(sys.executable, sys.executable, *sys.argv)

@bot.command()
async def shutdown():
bot.dev()
await bot.logout()
return exit(0)

if __name__ == "__main__": if __name__ == "__main__":
config = load_config() config = load_config()
bot.run(token) bot.run(token)

Loading…
Cancel
Save