From 0591aa583a476cd803e1e793e3546569a6b00363 Mon Sep 17 00:00:00 2001 From: Max Choi-Deyoung <34784905+maxchoid@users.noreply.github.com> Date: Mon, 16 Jul 2018 17:34:08 -0400 Subject: [PATCH] add some features maybe? --- cloud9_install.sh | 6 +++--- discordbot/config.example.py | 16 ++++++++-------- discordbot/run.py | 2 +- discordbot/titanembeds/bot.py | 28 ++++++++++++++-------------- discordbot/titanembeds/poststats.py | 6 +++--- webapp/config.example.py | 16 ++++++++-------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cloud9_install.sh b/cloud9_install.sh index 2b8c4e7..b87cd3c 100644 --- a/cloud9_install.sh +++ b/cloud9_install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -echo "[C9Setup] Installing postgresql, redis, and creating titan db table" +echo "[C9Setup] Installing PostGreSQL, redis, and creating titan db table" cd ~/workspace/ sudo service postgresql start psql -c "CREATE DATABASE titan WITH ENCODING 'UTF8' TEMPLATE template0" @@ -10,7 +10,7 @@ cp ~/workspace/webapp/config.example.py ~/workspace/webapp/config.py cp ~/workspace/discordbot/config.example.py ~/workspace/discordbot/config.py cp ~/workspace/webapp/alembic.example.ini ~/workspace/webapp/alembic.ini -echo "[C9Setup] Updating Python3.5" +echo "[C9Setup] Updating Python 3.5" sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install python3.5 @@ -39,7 +39,7 @@ sed -i "20s/.*/\'app-location\': \"\/home\/ubuntu\/workspace\/webapp\/\",/" ~/wo #'webosockets-mode': "eventlet", sed -i "25s/.*/\'websockets-mode\': \"eventlet\",/" ~/workspace/webapp/config.py -echo "[C9Setup] Making sure everything can be ran" +echo "[C9Setup] Testing..." cd ~/workspace/ sudo chmod -R 777 * diff --git a/discordbot/config.example.py b/discordbot/config.example.py index d8c13b6..6e6d33f 100644 --- a/discordbot/config.example.py +++ b/discordbot/config.example.py @@ -1,13 +1,13 @@ config = { - 'bot-token': "Discord bot token", - + 'bot-token': "Bot - Token", + 'database-uri': "driver://username:password@host:port/database", - + 'redis-uri': "redis://", - - 'discord-bots-org-token': "DiscordBots.org Post Stats Token", - - 'bots-discord-pw-token': "bots.discord.pw Post Stats Token", - + + 'discord-bots-org-token': "DiscordBots.org - Token", + + 'bots-discord-pw-token': "Discord Bots - Token", + 'logging-location': "/home/titan/Titan/discordbot/titanbot.log", } diff --git a/discordbot/run.py b/discordbot/run.py index c6b058c..18a2ab0 100644 --- a/discordbot/run.py +++ b/discordbot/run.py @@ -2,7 +2,7 @@ from titanembeds import Titan import gc def main(): - print("Starting...") + print("Starting bot...") te = Titan() te.run() gc.collect() diff --git a/discordbot/titanembeds/bot.py b/discordbot/titanembeds/bot.py index 76ba965..c3b40a3 100644 --- a/discordbot/titanembeds/bot.py +++ b/discordbot/titanembeds/bot.py @@ -23,9 +23,9 @@ class Titan(discord.AutoShardedClient): self.database = DatabaseInterface(self) self.command = Commands(self, self.database) self.socketio = SocketIOInterface(self, config["redis-uri"]) - + self.delete_list = deque(maxlen=100) # List of msg ids to prevent duplicate delete - + self.discordBotsOrg = None self.botsDiscordPw = None @@ -47,14 +47,14 @@ class Titan(discord.AutoShardedClient): try: self.loop.run_until_complete(self.start()) except discord.errors.LoginFailure: - print("Invalid bot token in config!") + print("Invalid bot token inside of the config!") finally: try: self._cleanup() except Exception as e: print("Error in cleanup:", e) self.loop.close() - + async def start(self): await self.database.connect(config["database-uri"]) await super().start(config["bot-token"]) @@ -67,10 +67,10 @@ class Titan(discord.AutoShardedClient): print('------') print("Shard count: " + str(self.shard_count)) print("------") - + game = discord.Game(name="Embed your Discord server! Visit https://TitanEmbeds.com/") await self.change_presence(status=discord.Status.online, activity=game) - + self.discordBotsOrg = DiscordBotsOrg(self.user.id, config.get("discord-bots-org-token", None)) self.botsDiscordPw = BotsDiscordPw(self.user.id, config.get("bots-discord-pw-token", None)) await self.postStats() @@ -182,7 +182,7 @@ class Titan(discord.AutoShardedClient): async def on_member_unban(self, guild, user): await self.database.unban_server_user(user, guild) - + async def on_guild_emojis_update(self, guild, before, after): if len(after) == 0: await self.database.update_guild(guild) @@ -190,10 +190,10 @@ class Titan(discord.AutoShardedClient): else: await self.database.update_guild(guild) await self.socketio.on_guild_emojis_update(after) - + async def on_webhooks_update(self, guild, channel): await self.database.update_guild(guild) - + async def on_raw_message_edit(self, payload): message_id = payload.message_id data = payload.data @@ -201,14 +201,14 @@ class Titan(discord.AutoShardedClient): channel = self.get_channel(int(data["channel_id"])) message = await channel.get_message(int(message_id)) await self.on_message_edit(None, message) - + async def on_raw_message_delete(self, payload): message_id = payload.message_id channel_id = payload.channel_id if not self.in_messages_cache(int(message_id)): await asyncio.sleep(1) await self.process_raw_message_delete(int(message_id), int(channel_id)) - + async def raw_bulk_message_delete(self, payload): message_ids = payload.message_ids channel_ids = payload.channel_id @@ -217,7 +217,7 @@ class Titan(discord.AutoShardedClient): msgid = int(msgid) if not self.in_messages_cache(msgid): await self.process_raw_message_delete(msgid, int(channel_id)) - + async def process_raw_message_delete(self, msg_id, channel_id): if msg_id in self.delete_list: self.delete_list.remove(msg_id) @@ -226,13 +226,13 @@ class Titan(discord.AutoShardedClient): data = {'content': "What fun is there in making sense?", 'type': 0, 'edited_timestamp': None, 'id': msg_id, 'channel_id': channel_id, 'timestamp': '2017-01-15T02:59:58+00:00'} msg = discord.Message(channel=channel, state=self._connection, data=data) # Procreate a fake message object await self.on_message_delete(msg) - + def in_messages_cache(self, msg_id): for msg in self._connection._messages: if msg.id == msg_id: return True return False - + async def postStats(self): count = len(self.guilds) shard_count = self.shard_count diff --git a/discordbot/titanembeds/poststats.py b/discordbot/titanembeds/poststats.py index fc263f4..e74581d 100644 --- a/discordbot/titanembeds/poststats.py +++ b/discordbot/titanembeds/poststats.py @@ -4,7 +4,7 @@ class DiscordBotsOrg(): # https://discordbots.org def __init__(self, client_id, token): self.url = "https://discordbots.org/api/bots/{}/stats".format(client_id) self.token = token - + async def post(self, count, shard_count, shard_id): headers = {"Authorization": self.token} payload = {"server_count": count, "shard_count": shard_count, "shard_no": shard_id} @@ -15,9 +15,9 @@ class BotsDiscordPw(): # https://bots.discord.pw/ def __init__(self, client_id, token): self.url = "https://bots.discord.pw/api/bots/{}/stats".format(client_id) self.token = token - + async def post(self, count, shard_count, shard_id): headers = {"Authorization": self.token} payload = {"server_count": count, "shard_count": shard_count, "shard_id": shard_id} async with aiohttp.ClientSession() as aioclient: - await aioclient.post(self.url, json=payload, headers=headers) \ No newline at end of file + await aioclient.post(self.url, json=payload, headers=headers) diff --git a/webapp/config.example.py b/webapp/config.example.py index 30a07fe..28951dc 100644 --- a/webapp/config.example.py +++ b/webapp/config.example.py @@ -1,18 +1,18 @@ config = { # Create an app over here https://discordapp.com/developers/applications/me # and fill these fields out - 'client-id': "Your app client id", - 'client-secret': "Your discord client secret", - 'bot-token': "Discord bot token", - + 'client-id': "Bot - Client ID", + 'client-secret': "Bot - Secret", + 'bot-token': "Bot - Token", + # Rest API in https://developer.paypal.com/developer/applications 'paypal-client-id': "Paypal client id", 'paypal-client-secret': "Paypal client secret", - + # V2 reCAPTCHA from https://www.google.com/recaptcha/admin 'recaptcha-site-key': "reCAPTCHA v2 Site Key", 'recaptcha-secret-key': "reCAPTCHA v2 Secret Key", - + # Patreon 'patreon-client-id': "Patreon client id", 'patreon-client-secret': "Patreon client secret", @@ -24,7 +24,7 @@ config = { 'redis-uri': "redis://", 'websockets-mode': "LITTERALLY None or eventlet or gevent", 'engineio-logging': False, - + # https://titanembeds.com/api/webhook/discordbotsorg/vote - 'discordbotsorg-webhook-secret': "Secret code used in the authorization header for DBL webhook", + 'discordbotsorg-webhook-secret': "Secret Code - Authencation Header", }