Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Directories #
.idea/*
__pycache__/
data/
logs/

# Files #
*.pyc
*.iml
*xml
*xml
settings\.json
27 changes: 7 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is a part of the official PyPI package directory and can be installed with

.. code:: bash

pip install discordbot.py
pip install discordbot.py


Examples
Expand All @@ -44,7 +44,7 @@ anyone that types ``!greet`` you can do the following:

@bot.event
async def on_member_join(member):
await bot.send_message(member.server, "Welcome {0.mention}, would you like to introduce yourself?".format(member))
await bot.send_message(member.server.default_channel, "Welcome {0}, would you like to introduce yourself?".format(member.mention))

@bot.command(pass_context=True)
async def greet(ctx):
Expand All @@ -54,8 +54,9 @@ anyone that types ``!greet`` you can do the following:
help is called on the command itself as opposed to the
normal short help which shows up in the main help.
"""
await bot.responses.say("Hi there, {0.mention}, how are you?".format(ctx.message.author))
await bot.send_message(ctx.message.channel, "Hi there, {0}, how are you?".format(ctx.message.author.mention))

bot.load_cogs()
bot.run()

This should be accompanied by a ``settings.json`` file like this:
Expand All @@ -71,7 +72,8 @@ This should be accompanied by a ``settings.json`` file like this:
"credentials": {
"token": "YOUR_TOKEN_HERE",
"client_id": "YOUR_CLIENT_ID"
}
},
"cogs": ["discordbot.cogs.meta", "discordbot.cogs.botadmin"]
}

Features
Expand Down Expand Up @@ -108,22 +110,7 @@ Your ``bot.py`` could be as minimal as this:
bot.load_cogs()
bot.run()

As long as you have a JSON file like this:

.. code:: json

{
"meta": {
"owner": "YOUR_ID",
"prefix": "ANY_PREFIX",
"description": "Optional description of the bot."
},
"credentials": {
"token": "YOUR_TOKEN_HERE",
"client_id": "YOUR_CLIENT_ID"
},
"cogs": ["cog_folder.cog_name", "cog_folder.another_cog"]
}
As long as you have a ``settings.json`` file with the proper data.

Through Python
^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions discordbot/bot_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# -*- coding: utf-8 -*-

from . import checks, config, formats, paginator
4 changes: 3 additions & 1 deletion discordbot/bot_utils/checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-

import discord.utils
from discord.ext import commands

from discordbot.bot_utils import config
from . import config

settings = config.Config('settings.json', directory="")
meta = settings.get('meta', {})
Expand Down
2 changes: 2 additions & 0 deletions discordbot/bot_utils/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import json
import os
import uuid
Expand Down
18 changes: 10 additions & 8 deletions discordbot/bot_utils/formats.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# -*- coding: utf-8 -*-

import datetime

async def entry_to_code(bot, entries):
width = max(map(lambda t: len(t[0]), entries))
output = ['```']
fmt = '{0:<{width}}: {1}'
fmt = '{name:<{width}}: {entry}'
for name, entry in entries:
output.append(fmt.format(name, entry, width=width))
output.append(fmt.format(name=name, entry=entry, width=width))
output.append('```')
await bot.say('\n'.join(output))

import datetime

async def indented_entry_to_code(bot, entries):
width = max(map(lambda t: len(t[0]), entries))
output = ['```']
fmt = '\u200b{0:>{width}}: {1}'
fmt = '\u200b{name:>{width}}: {entry}'
for name, entry in entries:
output.append(fmt.format(name, entry, width=width))
output.append(fmt.format(name=name, entry=entry, width=width))
output.append('```')
await bot.say('\n'.join(output))

Expand All @@ -30,7 +32,7 @@ async def too_many_matches(bot, msg, matches, entry):
try:
return matches[index - 1]
except:
await bot.say('Please give me a valid number. {} tries remaining...'.format(2 - i))
await bot.say('Please give me a valid number. {tries} tries remaining...'.format(tries = 2 - i))

raise ValueError('Too many tries. Goodbye.')

Expand Down Expand Up @@ -81,4 +83,4 @@ def title_case(string : str):
return ' '.join([s.strip().capitalize() for s in string.split(' ')]).strip()

def sentence_case(string : str):
return '. '.join([s.strip().capitalize() for s in string.split('.')]).strip()
return '. '.join([s.strip().capitalize() for s in string.split('.')]).strip()
2 changes: 2 additions & 0 deletions discordbot/bot_utils/paginator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import asyncio
import discord

Expand Down
Loading