Merge remote-tracking branch 'origin/development' into development

This commit is contained in:
Dustin Pianalto 2018-06-14 10:16:04 -08:00
commit 81c26742da
4 changed files with 80 additions and 49 deletions

View File

@ -27,13 +27,13 @@ This bot extends the rewrite version of discord.py. A couple of variables have b
Make sure this one is installed. Example: Make sure this one is installed. Example:
```py ```py
if self.bot.mainenance: if self.bot.maintenance:
print('I am in the development branch') print('I am in the development branch')
if not self.bot.mainenance: if not self.bot.maintenance:
print('I am in the master branch') print('I am in the master branch')
``` ```
In other words. `self.mainenance` returns `False` in production and `True` in developer modes. In other words. `self.maintenance` returns `False` in production and `True` in developer modes.
> `self.bot.embed_color` > `self.bot.embed_color`

View File

@ -19,6 +19,7 @@ from discord.ext import commands
from src.config.config import LoadConfig from src.config.config import LoadConfig
from src.shared_libs.loggable import Loggable from src.shared_libs.loggable import Loggable
from src.shared_libs.ioutils import in_here from src.shared_libs.ioutils import in_here
from src.shared_libs import database
# Init logging to output on INFO level to stderr. # Init logging to output on INFO level to stderr.
@ -52,6 +53,9 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
# Initialize and attach config / settings # Initialize and attach config / settings
LoadConfig.__init__(self) LoadConfig.__init__(self)
commands.Bot.__init__(self, command_prefix=self.defaultprefix) commands.Bot.__init__(self, command_prefix=self.defaultprefix)
with open(in_here('config', 'PrivateConfig.json')) as fp:
self.bot_secrets = json.load(fp)
self.db_con = database.DatabaseConnection(**self.bot_secrets['db-con'])
# Load plugins # Load plugins
# Add your cog file name in this list # Add your cog file name in this list
@ -134,11 +138,5 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
client = SebiMachine() client = SebiMachine()
# Make sure the key stays private.
# I am 99% certain this is valid!
with open(in_here('config', 'PrivateConfig.json')) as fp:
PrivateConfig = json.load(fp)
if PrivateConfig["bot-key"] == '':
PrivateConfig["bot-key"] = os.getenv('botkey')
client.run(PrivateConfig["bot-key"]) client.run(client.bot_secrets["bot-key"])

View File

@ -3,6 +3,7 @@
from discord.ext import commands from discord.ext import commands
import discord import discord
import asyncio
class BasicCommands: class BasicCommands:
def __init__(self, bot): def __init__(self, bot):
@ -29,26 +30,35 @@ class BasicCommands:
msg = await self.bot.wait_for('message', check = check, timeout = 15) msg = await self.bot.wait_for('message', check = check, timeout = 15)
agree = ("yes", "yep", "yesn't", "ya") agree = ("yes", "yep", "yesn't", "ya", "ye")
if msg is None: if msg is None:
await ctx.send("Sorry, {ctx.author.mention}, you didn't reply on time. You can run the command again when you're free :)") await ctx.send("Sorry, {ctx.author.mention}, you didn't reply on time. You can run the command again when you're free :)")
else: else:
if msg.content.lower() in agree: if msg.content.lower() in agree:
async with ctx.typing(): async with ctx.typing():
await ctx.send("Alrighty-Roo...") await ctx.send("Alrighty-Roo... Check your DMs!")
await ctx.send(f"""To start making your bot from scratch, you first need to head over to {channel_list['channel-1']} await ctx.author.send("Alrighty-Roo...")
(Regardless of the language you're gonna use).""")
await ctx.send(f"""After you have a bot account, you can either continue with {channel_list['d.py-rewrite-start']} await ctx.author.send(f"To start making your bot from scratch, you first need to head over to {channel_list['channel-1']}"
if you want to make a bot in discord.py rewrite __or__ go to {channel_list['js-klasa-start']} or " (Regardless of the language you're gonna use).")
{channel_list['d.js']} for making a bot in JavaScript""")
await ctx.send("...Read all the tutorials and still need help? You have two ways to get help.") await asyncio.sleep(0.5)
await ctx.send(f"""**Method-1**\nThis is the best method of getting help. You help yourself.\n await ctx.author.send(f"After you have a bot account, you can either continue with {channel_list['d.py-rewrite-start']}"
To do so, head over to a bots dedicated channel (either {bots_channels[0]} or {bots_channels[1]}) f"if you want to make a bot in discord.py rewrite __or__ go to {channel_list['js-klasa-start']} or "
and type `?rtfm rewrite thing_you_want_help_with`.\nThis will trigger the bot R.Danny Bot and will f"{channel_list['d.js']} for making a bot in JavaScript.")
give you links on your query on the official discord.py rewrite docs. *PS: Let the page completely load*""")
await ctx.send(f"""**Method-2**\nIf you haven't found anything useful with Method-1, feel free to ask your question await ctx.author.send("...Read all the tutorials and still need help? You have two ways to get help.")
in any of the related help channels. ({', '.join(help_channels)})\nMay the force be with you!!""") await asyncio.sleep(1.5)
await ctx.author.send("**Method-1**\nThis is the best method of getting help. You help yourself.\n"
f"To do so, head over to a bots dedicated channel (either {bots_channels[0]} or {bots_channels[1]})"
" and type `?rtfm rewrite thing_you_want_help_with`.\nThis will trigger the bot R.Danny Bot and will"
"give you links on your query on the official discord.py rewrite docs. *PS: Let the page completely load*")
await asyncio.sleep(5)
await ctx.author.send("**Method-2**\nIf you haven't found anything useful with Method-1, feel free to ask your question "
f"in any of the related help channels. ({', '.join(help_channels)})\nMay the force be with you!!")
else: else:
return await ctx.send("Session terminated. You can run this command again whenever you want.") return await ctx.send("Session terminated. You can run this command again whenever you want.")

View File

@ -0,0 +1,23 @@
import asyncpg
import asyncio
class DatabaseConnection:
def __init__(self, host: str='localhost', port: int=5432, database: str='', user: str='', password: str=''):
if user == '' or password == '' or database == '':
raise RuntimeError('Username or Password are blank')
self.kwargs = {'host': host, 'port': port, 'database': database, 'user': user, 'password': password}
self._conn = None
asyncio.get_event_loop().run_until_complete(self.acquire())
self.fetchval = self._conn.fetchval
self.execute = self._conn.execute
self.fetch = self._conn.fetch
self.fetchrow = self._conn.fetchrow
async def acquire(self):
if not self._conn:
self._conn = await asyncpg.create_pool(**self.kwargs)
async def close(self):
await self._conn.close()
self._conn = None