From 37dd0950a5b17964f443225752319e9c05dc7ea4 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 1 Dec 2018 18:25:53 -0600 Subject: [PATCH] Bot now starts automatically +subprocess kicked off when URLs are being loaded +renamed bot dir to discord_bot --- api/commands.py | 4 ++-- api/{bot => discord_bot}/BotErrors.py | 0 api/{bot => discord_bot}/DiscordHelperFunctions.py | 0 .../MinecraftAccountInfoGrabber.py | 2 +- api/{bot => discord_bot}/__init__.py | 0 api/{bot => discord_bot}/bot.py | 13 +++++++------ api/{bot => discord_bot}/cogs/Add_Commands.py | 2 +- api/{bot => discord_bot}/cogs/Admin_Commands.py | 6 +++--- api/{bot => discord_bot}/cogs/Delete_Commands.py | 0 api/{bot => discord_bot}/cogs/Edit_Commands.py | 0 api/{bot => discord_bot}/cogs/Search_Commands.py | 4 ++-- api/{bot => discord_bot}/cogs/__init__.py | 0 api/views.py | 2 +- assets/bots/geoffrey.py | 14 -------------- models.py | 1 + urls.py | 9 ++++++++- 16 files changed, 26 insertions(+), 31 deletions(-) rename api/{bot => discord_bot}/BotErrors.py (100%) rename api/{bot => discord_bot}/DiscordHelperFunctions.py (100%) rename api/{bot => discord_bot}/MinecraftAccountInfoGrabber.py (91%) rename api/{bot => discord_bot}/__init__.py (100%) rename api/{bot => discord_bot}/bot.py (92%) rename api/{bot => discord_bot}/cogs/Add_Commands.py (99%) rename api/{bot => discord_bot}/cogs/Admin_Commands.py (96%) rename api/{bot => discord_bot}/cogs/Delete_Commands.py (100%) rename api/{bot => discord_bot}/cogs/Edit_Commands.py (100%) rename api/{bot => discord_bot}/cogs/Search_Commands.py (97%) rename api/{bot => discord_bot}/cogs/__init__.py (100%) delete mode 100755 assets/bots/geoffrey.py diff --git a/api/commands.py b/api/commands.py index cde7c2e..a202a80 100644 --- a/api/commands.py +++ b/api/commands.py @@ -1,7 +1,7 @@ -from GeoffreyApp.api.bot.BotErrors import * +from GeoffreyApp.api.discord_bot.BotErrors import * from django.db.models import Q, F from GeoffreyApp.models import * -from GeoffreyApp.api.bot.MinecraftAccountInfoGrabber import * +from GeoffreyApp.api.discord_bot.MinecraftAccountInfoGrabber import * post_list = [] get_list = [] diff --git a/api/bot/BotErrors.py b/api/discord_bot/BotErrors.py similarity index 100% rename from api/bot/BotErrors.py rename to api/discord_bot/BotErrors.py diff --git a/api/bot/DiscordHelperFunctions.py b/api/discord_bot/DiscordHelperFunctions.py similarity index 100% rename from api/bot/DiscordHelperFunctions.py rename to api/discord_bot/DiscordHelperFunctions.py diff --git a/api/bot/MinecraftAccountInfoGrabber.py b/api/discord_bot/MinecraftAccountInfoGrabber.py similarity index 91% rename from api/bot/MinecraftAccountInfoGrabber.py rename to api/discord_bot/MinecraftAccountInfoGrabber.py index d39c483..c864ac8 100644 --- a/api/bot/MinecraftAccountInfoGrabber.py +++ b/api/discord_bot/MinecraftAccountInfoGrabber.py @@ -2,7 +2,7 @@ from simplejson.errors import JSONDecodeError import requests -from GeoffreyApp.api.bot.BotErrors import UsernameLookupFailed +from GeoffreyApp.api.discord_bot.BotErrors import UsernameLookupFailed uuid_lookup_url = 'https://api.mojang.com/users/profiles/minecraft/{}' username_lookup_url = 'https://api.mojang.com/user/profiles/{}/names' diff --git a/api/bot/__init__.py b/api/discord_bot/__init__.py similarity index 100% rename from api/bot/__init__.py rename to api/discord_bot/__init__.py diff --git a/api/bot/bot.py b/api/discord_bot/bot.py similarity index 92% rename from api/bot/bot.py rename to api/discord_bot/bot.py index 9e17ba1..8726db9 100644 --- a/api/bot/bot.py +++ b/api/discord_bot/bot.py @@ -8,7 +8,7 @@ import logging.handlers as handlers from sys import stdout from os import path -from GeoffreyApp.api.bot.BotErrors import * +from GeoffreyApp.api.discord_bot.BotErrors import * from GeoffreyApp.api.commands import * from django.conf import settings @@ -16,9 +16,9 @@ logger = logging.getLogger(__name__) description = ''' Geoffrey (pronounced JOFF-ree) started his life as an inside joke none of you will understand. -At some point, she was to become an airhorn bot. Now, they know where your stuff is. +At some point, she was to become an airhorn discord_bot. Now, they know where your stuff is. -Please respect Geoffrey, the bot is very sensitive. +Please respect Geoffrey, the discord_bot is very sensitive. All commands must be prefaced with '?' @@ -26,7 +26,7 @@ If have a suggestion or if something is borked, you can PM my ding dong of a cre *You must use ?register before adding things to Geoffrey* -For a better a explanation on how this bot works go the following link: +For a better a explanation on how this discord_bot works go the following link: https://github.com/joeyahines/Geoffrey/blob/master/README.md ''' @@ -132,7 +132,7 @@ class GeoffreyBot(commands.Bot): def setup_logging(): discord_logger = logging.getLogger('discord') discord_logger.setLevel(logging.INFO) - bot_info_logger = logging.getLogger('GeoffreyApp.api.bot.bot') + bot_info_logger = logging.getLogger('GeoffreyApp.api.discord_bot.discord_bot') bot_info_logger.setLevel(logging.INFO) console = logging.StreamHandler(stdout) console.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) @@ -141,6 +141,7 @@ def setup_logging(): def start_bot(): + asyncio.set_event_loop(asyncio.new_event_loop()) bot = None try: bot = GeoffreyBot() @@ -148,7 +149,7 @@ def start_bot(): @bot.command(pass_context=True) async def test(ctx): """ - Checks if the bot is alive. + Checks if the discord_bot is alive. """ await ctx.send('I\'m here you ding dong') diff --git a/api/bot/cogs/Add_Commands.py b/api/discord_bot/cogs/Add_Commands.py similarity index 99% rename from api/bot/cogs/Add_Commands.py rename to api/discord_bot/cogs/Add_Commands.py index f584cd1..94f95c7 100644 --- a/api/bot/cogs/Add_Commands.py +++ b/api/discord_bot/cogs/Add_Commands.py @@ -25,7 +25,7 @@ class Add_Commands: try: player_name = get_nickname(ctx.message.author, self.bot.special_users) self.bot.bot_commands.register(player_name, ctx.message.author.id) - await ctx.send('{}, you have been added to the database. Use ?help to see all the commands this bot can do.' + await ctx.send('{}, you have been added to the database. Use ?help to see all the commands this discord_bot can do.' .format(ctx.message.author.mention)) except AttributeError: raise NotOnServerError diff --git a/api/bot/cogs/Admin_Commands.py b/api/discord_bot/cogs/Admin_Commands.py similarity index 96% rename from api/bot/cogs/Admin_Commands.py rename to api/discord_bot/cogs/Admin_Commands.py index 50c91aa..ec0a028 100644 --- a/api/bot/cogs/Admin_Commands.py +++ b/api/discord_bot/cogs/Admin_Commands.py @@ -34,14 +34,14 @@ class Admin_Commands: error_str = 'that player does not have a location by that name.' if error_str is "": - error_str = 'the bot encountered the following error: {}'.format(error.__str__()) + error_str = 'the discord_bot encountered the following error: {}'.format(error.__str__()) await ctx.send('{}, {}'.format(ctx.message.author.mention, error_str)) @commands.command(pass_context=True) async def test(self, ctx): """ - Checks if the bot is alive. + Checks if the discord_bot is alive. """ if check_mod(ctx.message.author, self.bot.admin_users): await ctx.send('I\'m here you ding dong') @@ -123,7 +123,7 @@ class Admin_Commands: @mod.command(pass_context=True) async def status(self, ctx, *args): """ - Updates "playing [game]" status of the bot + Updates "playing [game]" status of the discord_bot """ status = get_name(args) await self.bot.change_presence(activity=Game(status)) diff --git a/api/bot/cogs/Delete_Commands.py b/api/discord_bot/cogs/Delete_Commands.py similarity index 100% rename from api/bot/cogs/Delete_Commands.py rename to api/discord_bot/cogs/Delete_Commands.py diff --git a/api/bot/cogs/Edit_Commands.py b/api/discord_bot/cogs/Edit_Commands.py similarity index 100% rename from api/bot/cogs/Edit_Commands.py rename to api/discord_bot/cogs/Edit_Commands.py diff --git a/api/bot/cogs/Search_Commands.py b/api/discord_bot/cogs/Search_Commands.py similarity index 97% rename from api/bot/cogs/Search_Commands.py rename to api/discord_bot/cogs/Search_Commands.py index ab1b0cb..82d765d 100644 --- a/api/bot/cogs/Search_Commands.py +++ b/api/discord_bot/cogs/Search_Commands.py @@ -1,7 +1,7 @@ from discord.ext import commands -from geoffrey.BotErrors import * -from geoffrey.DiscordHelperFunctions import * +from GeoffreyApp.api.discord_bot.BotErrors import * +from GeoffreyApp.api.discord_bot.DiscordHelperFunctions import * class Search_Commands: diff --git a/api/bot/cogs/__init__.py b/api/discord_bot/cogs/__init__.py similarity index 100% rename from api/bot/cogs/__init__.py rename to api/discord_bot/cogs/__init__.py diff --git a/api/views.py b/api/views.py index bf040e8..3776cab 100644 --- a/api/views.py +++ b/api/views.py @@ -2,7 +2,7 @@ from django.views.generic import View from django.http import JsonResponse import GeoffreyApp.api.commands as commands -from GeoffreyApp.api.bot.BotErrors import * +from GeoffreyApp.api.discord_bot.BotErrors import * def run_command(request, command, command_list): diff --git a/assets/bots/geoffrey.py b/assets/bots/geoffrey.py deleted file mode 100755 index 44d1baa..0000000 --- a/assets/bots/geoffrey.py +++ /dev/null @@ -1,14 +0,0 @@ -import os - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Geoffrey.settings") - -if __name__ == '__main__': - import django - django.setup() - from GeoffreyApp.api.bot.bot import start_bot - - start_bot() - - - - diff --git a/models.py b/models.py index f53be05..26ac7e6 100644 --- a/models.py +++ b/models.py @@ -4,6 +4,7 @@ from sys import maxsize # Create your models here. + class Player(models.Model): name = models.CharField(max_length=30, unique=True) mc_uuid = models.CharField(max_length=36, unique=True) diff --git a/urls.py b/urls.py index 3ef24d9..9b18fae 100644 --- a/urls.py +++ b/urls.py @@ -1,7 +1,14 @@ from django.urls import path +from multiprocessing import Process +from GeoffreyApp.api.discord_bot.bot import start_bot + from . import views urlpatterns = [ path('', views.index, name='index'), -] \ No newline at end of file +] + +p = Process(target=start_bot) +p.start() +print("Thread start...") \ No newline at end of file