From 7e3fe20a595889d4afefffa4ab5bb513f318d7df Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 18:54:10 -0400 Subject: [PATCH 01/14] change config to port based --- config.ini | 2 +- constants.py | 2 +- main.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 42588b9..0517007 100644 --- a/config.ini +++ b/config.ini @@ -8,4 +8,4 @@ channel_id = 0 webhook_url = '' [flask] -run_locally = true \ No newline at end of file +local_port = true \ No newline at end of file diff --git a/constants.py b/constants.py index ab3529e..4e13ff3 100644 --- a/constants.py +++ b/constants.py @@ -19,7 +19,7 @@ def get_constant( return constant -RUN_LOCAL = config.getboolean('flask', 'run_locally') +LOCAL_PORT = config.getboolean('flask', 'local_port') GROUPME_ID = get_constant('GROUPME_ID', 'groupme', 'bot_id') BOT_TOKEN = get_constant('DISCORD_BOT_TOKEN', 'discord', 'bot_token') WEBHOOK_URL = get_constant('DISCORD_WEBHOOK', 'discord', 'webhook_url') diff --git a/main.py b/main.py index b4b80af..bb5c999 100644 --- a/main.py +++ b/main.py @@ -8,8 +8,8 @@ flask_options = {} -if not RUN_LOCAL: - flask_options = {'host': '0.0.0.0'} +if LOCAL_PORT: + flask_options = {'host': '0.0.0.0',port=LOCAL_PORT} discord_bot.main() web_server.main(**flask_options) From 4f079f20a01f6094bad873a5d7c2426256a40784 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 18:55:52 -0400 Subject: [PATCH 02/14] ignore config.ini to prevent exposing creds --- config.ini | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 config.ini diff --git a/config.ini b/config.ini deleted file mode 100644 index 0517007..0000000 --- a/config.ini +++ /dev/null @@ -1,11 +0,0 @@ -[groupme] -bot_id = '' -access_token = '' - -[discord] -bot_token = '' -channel_id = 0 -webhook_url = '' - -[flask] -local_port = true \ No newline at end of file From 8b498d7ed234b7ed3f4a45e18b73a63afdfff232 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:15:17 -0400 Subject: [PATCH 03/14] change to channel name instead of id fix local port make all constants flow through mani --- .gitignore | 1 + .vscode/settings.json | 3 +++ constants.py | 4 ++-- discord_bot.py | 9 +++++---- main.py | 8 ++++---- web_server.py | 4 +++- 6 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2fa7ce7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.ini diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b26f7c4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/bin/python" +} \ No newline at end of file diff --git a/constants.py b/constants.py index 4e13ff3..d78d4e0 100644 --- a/constants.py +++ b/constants.py @@ -19,9 +19,9 @@ def get_constant( return constant -LOCAL_PORT = config.getboolean('flask', 'local_port') +LOCAL_PORT = get_constant('flask', 'local_port') GROUPME_ID = get_constant('GROUPME_ID', 'groupme', 'bot_id') BOT_TOKEN = get_constant('DISCORD_BOT_TOKEN', 'discord', 'bot_token') WEBHOOK_URL = get_constant('DISCORD_WEBHOOK', 'discord', 'webhook_url') GROUPME_TOKEN = get_constant('GROUPME_TOKEN', 'groupme', 'access_token') -CHANNEL_ID = get_constant('DISCORD_CHANNEL_ID', 'discord', 'channel_id') +CHANNEL_NAME = get_constant('DISCORD_CHANNEL_NAME', 'discord', 'channel_name') diff --git a/discord_bot.py b/discord_bot.py index 411e4af..93866b1 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -12,8 +12,6 @@ from aiohttp import ClientSession from discord import Attachment, Message -from constants import BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_ID - async def post( session: ClientSession, url: str, @@ -87,13 +85,16 @@ async def on_ready() -> None: @bot.event async def on_message(message: Message) -> None: """Called on each message sent in a channel.""" - if message.channel.id == CHANNEL_ID: + if CHANNEL_NAME in str(message.channel): if not message.author.bot: print(await send_message(message)) elif message.content in sent_buffer: await message.delete() -def main(): +def main(botToken, groupmeToken, groupmeID, channelName): + global BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME + BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME = botToken,groupmeToken,groupmeID,channelID + """Start the bot with the provided token.""" Process(target=bot.run, args=(BOT_TOKEN,)).start() diff --git a/main.py b/main.py index bb5c999..0d99132 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,13 @@ import web_server import discord_bot -from constants import RUN_LOCAL +from constants import * flask_options = {} -if LOCAL_PORT: +if "false" now in LOCAL_PORT: flask_options = {'host': '0.0.0.0',port=LOCAL_PORT} -discord_bot.main() -web_server.main(**flask_options) +discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) +web_server.main(WEBHOOK_URL,**flask_options) diff --git a/web_server.py b/web_server.py index 51c3c70..588390f 100644 --- a/web_server.py +++ b/web_server.py @@ -26,6 +26,8 @@ def index(): return '' -def main(*args, **kwargs): +def main(webhookURL,*args, **kwargs): + global WEBHOOK_URL + WEBHOOK_URL = webhookURL """Start the webserver with the provided options.""" Process(target=app.run, args=args, kwargs=kwargs).start() From 652d47a45b9a6d5c8a688c121096cdc91c2f806f Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:33:51 -0400 Subject: [PATCH 04/14] bugfixes --- constants.py | 2 +- discord_bot.py | 2 +- main.py | 4 ++-- web_server.py | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/constants.py b/constants.py index d78d4e0..ca0aa6d 100644 --- a/constants.py +++ b/constants.py @@ -19,7 +19,7 @@ def get_constant( return constant -LOCAL_PORT = get_constant('flask', 'local_port') +LOCAL_PORT = get_constant('LOCAL_PORT','flask', 'local_port') GROUPME_ID = get_constant('GROUPME_ID', 'groupme', 'bot_id') BOT_TOKEN = get_constant('DISCORD_BOT_TOKEN', 'discord', 'bot_token') WEBHOOK_URL = get_constant('DISCORD_WEBHOOK', 'discord', 'webhook_url') diff --git a/discord_bot.py b/discord_bot.py index 93866b1..08c6e5c 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -94,7 +94,7 @@ async def on_message(message: Message) -> None: def main(botToken, groupmeToken, groupmeID, channelName): global BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME - BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME = botToken,groupmeToken,groupmeID,channelID + BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME = botToken,groupmeToken,groupmeID,channelName """Start the bot with the provided token.""" Process(target=bot.run, args=(BOT_TOKEN,)).start() diff --git a/main.py b/main.py index 0d99132..da36844 100644 --- a/main.py +++ b/main.py @@ -8,8 +8,8 @@ flask_options = {} -if "false" now in LOCAL_PORT: - flask_options = {'host': '0.0.0.0',port=LOCAL_PORT} +if "false" in str(LOCAL_PORT): + flask_options = {'host': '0.0.0.0',port: LOCAL_PORT} discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) web_server.main(WEBHOOK_URL,**flask_options) diff --git a/web_server.py b/web_server.py index 588390f..48b815a 100644 --- a/web_server.py +++ b/web_server.py @@ -6,7 +6,6 @@ import requests from flask import Flask, request -from constants import WEBHOOK_URL app = Flask(__name__) From c85fe57a20ce982c323b6efb63df6a06012f6def Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:44:45 -0400 Subject: [PATCH 05/14] refactor main --- main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index da36844..aa8fb43 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,27 @@ import web_server import discord_bot -from constants import * +from constants import BOT_TOKEN, GROUPME_TOKEN #set as environment variables +settings = [ + { + 'bot_id': "60d8f6e70e5fe17ff5e236e072", #groupme + 'channel_name': "cs_memes", #discord + 'webhook_url': "https://discordapp.com/api/webhooks/730924768769081457/wB3rLeUJKnUrfk4clQaaYJ2eVHGm6WhJa2lLICSerHvBl4fYFmYhShaligTWknbK-h88", + 'local_port': 50070 #server + } +] +for instance in settings: -flask_options = {} + GROUPME_ID=instance['bot_id'] + CHANNEL_NAME=instance['channel_name'] + WEBHOOK_URL=instance['webhook_url'] + LOCAL_PORT=instance['local_port'] -if "false" in str(LOCAL_PORT): - flask_options = {'host': '0.0.0.0',port: LOCAL_PORT} + flask_options = {} -discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) -web_server.main(WEBHOOK_URL,**flask_options) + if "false" in str(LOCAL_PORT): + flask_options = {'host': '0.0.0.0', port: LOCAL_PORT} + + discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) + web_server.main(WEBHOOK_URL, **flask_options) From 924fc7f9b711e5a56a5c927e9d7e1fd68d79ccaa Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:53:48 -0400 Subject: [PATCH 06/14] redo constants to env var only --- constants.py | 13 ++----------- main.py | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/constants.py b/constants.py index ca0aa6d..3656b81 100644 --- a/constants.py +++ b/constants.py @@ -2,26 +2,17 @@ from os import environ from typing import Union -from configparser import ConfigParser - - -config = ConfigParser() -config.read('config.ini') def get_constant( env_name: str, config_header: str, config_key: str ) -> Union[str, int]: """Get a constant from the environment or config.""" - constant = environ.get(env_name) or config.get(config_header, config_key) + constant = environ.get(env_name) if constant.isnumeric(): constant = int(constant) return constant -LOCAL_PORT = get_constant('LOCAL_PORT','flask', 'local_port') -GROUPME_ID = get_constant('GROUPME_ID', 'groupme', 'bot_id') BOT_TOKEN = get_constant('DISCORD_BOT_TOKEN', 'discord', 'bot_token') -WEBHOOK_URL = get_constant('DISCORD_WEBHOOK', 'discord', 'webhook_url') -GROUPME_TOKEN = get_constant('GROUPME_TOKEN', 'groupme', 'access_token') -CHANNEL_NAME = get_constant('DISCORD_CHANNEL_NAME', 'discord', 'channel_name') +GROUPME_TOKEN = get_constant('GROUPME_TOKEN', 'groupme', 'access_token') \ No newline at end of file diff --git a/main.py b/main.py index aa8fb43..d6c7550 100644 --- a/main.py +++ b/main.py @@ -3,27 +3,31 @@ import web_server import discord_bot -from constants import BOT_TOKEN, GROUPME_TOKEN #set as environment variables +from constants import BOT_TOKEN, GROUPME_TOKEN # set as environment variables + +#GROUPME_TOKEN=groupme token here +#DISCORD_BOT_TOKEN=discord bot token + settings = [ - { - 'bot_id': "60d8f6e70e5fe17ff5e236e072", #groupme - 'channel_name': "cs_memes", #discord + { + 'bot_id': "60d8f6e70e5fe17ff5e236e072", # groupme + 'channel_name': "cs_memes", # discord 'webhook_url': "https://discordapp.com/api/webhooks/730924768769081457/wB3rLeUJKnUrfk4clQaaYJ2eVHGm6WhJa2lLICSerHvBl4fYFmYhShaligTWknbK-h88", - 'local_port': 50070 #server + 'local_port': 50070 # server } ] for instance in settings: - GROUPME_ID=instance['bot_id'] - CHANNEL_NAME=instance['channel_name'] - WEBHOOK_URL=instance['webhook_url'] - LOCAL_PORT=instance['local_port'] + GROUPME_ID = instance['bot_id'] + CHANNEL_NAME = instance['channel_name'] + WEBHOOK_URL = instance['webhook_url'] + LOCAL_PORT = instance['local_port'] flask_options = {} - if "false" in str(LOCAL_PORT): - flask_options = {'host': '0.0.0.0', port: LOCAL_PORT} + if "false" not in str(LOCAL_PORT): + flask_options = {'host': '0.0.0.0', 'port': LOCAL_PORT} discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) web_server.main(WEBHOOK_URL, **flask_options) From 4f292a42ba47174a9c3048e694fd8fb89d21c415 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:57:37 -0400 Subject: [PATCH 07/14] updated credential structrue --- .gitignore | 2 +- credentials.py.sample | 13 +++++++++++++ main.py | 16 ++-------------- 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 credentials.py.sample diff --git a/.gitignore b/.gitignore index 2fa7ce7..928acbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -config.ini +credentials.py \ No newline at end of file diff --git a/credentials.py.sample b/credentials.py.sample new file mode 100644 index 0000000..3419fae --- /dev/null +++ b/credentials.py.sample @@ -0,0 +1,13 @@ +#edit settings and copy this to credentials.py +GROUPME_TOKEN="groupme token here" +DISCORD_BOT_TOKEN="discord bot token" + + +settings = [ + { + 'bot_id': "groupme bot id", # groupme + 'channel_name': "cs_memes", # discord + 'webhook_url': "discord webhook url", + 'local_port': 42069 # server internal port + } +] \ No newline at end of file diff --git a/main.py b/main.py index d6c7550..1e00f16 100644 --- a/main.py +++ b/main.py @@ -3,22 +3,10 @@ import web_server import discord_bot -from constants import BOT_TOKEN, GROUPME_TOKEN # set as environment variables +from credentials import * -#GROUPME_TOKEN=groupme token here -#DISCORD_BOT_TOKEN=discord bot token - -settings = [ - { - 'bot_id': "60d8f6e70e5fe17ff5e236e072", # groupme - 'channel_name': "cs_memes", # discord - 'webhook_url': "https://discordapp.com/api/webhooks/730924768769081457/wB3rLeUJKnUrfk4clQaaYJ2eVHGm6WhJa2lLICSerHvBl4fYFmYhShaligTWknbK-h88", - 'local_port': 50070 # server - } -] for instance in settings: - GROUPME_ID = instance['bot_id'] CHANNEL_NAME = instance['channel_name'] WEBHOOK_URL = instance['webhook_url'] @@ -27,7 +15,7 @@ flask_options = {} if "false" not in str(LOCAL_PORT): - flask_options = {'host': '0.0.0.0', 'port': LOCAL_PORT} + flask_options = {'host': '127.0.0.1', 'port': LOCAL_PORT} discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) web_server.main(WEBHOOK_URL, **flask_options) From e5f5b1c1064223605225ad8644dc9f22f1b6764c Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:58:24 -0400 Subject: [PATCH 08/14] update credential sample --- credentials.py.sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/credentials.py.sample b/credentials.py.sample index 3419fae..baaf0e5 100644 --- a/credentials.py.sample +++ b/credentials.py.sample @@ -1,7 +1,9 @@ #edit settings and copy this to credentials.py + +### SUPER SECRET ### GROUPME_TOKEN="groupme token here" DISCORD_BOT_TOKEN="discord bot token" - +### SUPER SECRET END ### settings = [ { From d9cd36caeac2e5fb450baeafe9e9c6f2dc046439 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 20:00:47 -0400 Subject: [PATCH 09/14] update sample creds --- constants.py | 18 ------------------ credentials.py.sample | 4 ++-- 2 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 constants.py diff --git a/constants.py b/constants.py deleted file mode 100644 index 3656b81..0000000 --- a/constants.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Parse constants from the config file and environment variables.""" - -from os import environ -from typing import Union - - -def get_constant( - env_name: str, config_header: str, config_key: str -) -> Union[str, int]: - """Get a constant from the environment or config.""" - constant = environ.get(env_name) - if constant.isnumeric(): - constant = int(constant) - return constant - - -BOT_TOKEN = get_constant('DISCORD_BOT_TOKEN', 'discord', 'bot_token') -GROUPME_TOKEN = get_constant('GROUPME_TOKEN', 'groupme', 'access_token') \ No newline at end of file diff --git a/credentials.py.sample b/credentials.py.sample index baaf0e5..19f2d9b 100644 --- a/credentials.py.sample +++ b/credentials.py.sample @@ -7,9 +7,9 @@ DISCORD_BOT_TOKEN="discord bot token" settings = [ { - 'bot_id': "groupme bot id", # groupme + 'bot_id': "groupme_bot_id", 'channel_name': "cs_memes", # discord - 'webhook_url': "discord webhook url", + 'webhook_url': "discord_webhook_url", 'local_port': 42069 # server internal port } ] \ No newline at end of file From 051ed9a7f2573bbbf21e8d0fd91063b7d9b5b58c Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 21:29:21 -0400 Subject: [PATCH 10/14] finalupdate --- credentials.py.sample | 2 +- main.py | 2 ++ removefile | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 removefile diff --git a/credentials.py.sample b/credentials.py.sample index 19f2d9b..e25f46c 100644 --- a/credentials.py.sample +++ b/credentials.py.sample @@ -2,7 +2,7 @@ ### SUPER SECRET ### GROUPME_TOKEN="groupme token here" -DISCORD_BOT_TOKEN="discord bot token" +BOT_TOKEN="discord bot token" ### SUPER SECRET END ### settings = [ diff --git a/main.py b/main.py index 1e00f16..a301f5c 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import web_server import discord_bot +import time from credentials import * @@ -19,3 +20,4 @@ discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) web_server.main(WEBHOOK_URL, **flask_options) + time.sleep(2) diff --git a/removefile b/removefile new file mode 100644 index 0000000..42e22ff --- /dev/null +++ b/removefile @@ -0,0 +1 @@ + regex:/api/webhooks.* From 708a674e320df9100e517454edc9dda4e8285deb Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 19:44:45 -0400 Subject: [PATCH 11/14] refactor main make it work with updated config --- main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index da36844..aa8fb43 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,27 @@ import web_server import discord_bot -from constants import * +from constants import BOT_TOKEN, GROUPME_TOKEN #set as environment variables +settings = [ + { + 'bot_id': "60d8f6e70e5fe17ff5e236e072", #groupme + 'channel_name': "cs_memes", #discord + 'webhook_url': "https://discordapp.com/api/webhooks/730924768769081457/wB3rLeUJKnUrfk4clQaaYJ2eVHGm6WhJa2lLICSerHvBl4fYFmYhShaligTWknbK-h88", + 'local_port': 50070 #server + } +] +for instance in settings: -flask_options = {} + GROUPME_ID=instance['bot_id'] + CHANNEL_NAME=instance['channel_name'] + WEBHOOK_URL=instance['webhook_url'] + LOCAL_PORT=instance['local_port'] -if "false" in str(LOCAL_PORT): - flask_options = {'host': '0.0.0.0',port: LOCAL_PORT} + flask_options = {} -discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) -web_server.main(WEBHOOK_URL,**flask_options) + if "false" in str(LOCAL_PORT): + flask_options = {'host': '0.0.0.0', port: LOCAL_PORT} + + discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) + web_server.main(WEBHOOK_URL, **flask_options) From cb44cf037160c63a7f988f99f0d6ceeba02a51cd Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 9 Jul 2020 21:38:50 -0400 Subject: [PATCH 12/14] updated credential structrue sample credentials and minor usability updates update sample creds finalupdate done update credential sample redo constants to env var only --- .gitignore | 2 +- constants.py | 27 --------------------------- credentials.py.sample | 15 +++++++++++++++ main.py | 26 ++++++++++---------------- 4 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 constants.py create mode 100644 credentials.py.sample diff --git a/.gitignore b/.gitignore index 2fa7ce7..928acbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -config.ini +credentials.py \ No newline at end of file diff --git a/constants.py b/constants.py deleted file mode 100644 index ca0aa6d..0000000 --- a/constants.py +++ /dev/null @@ -1,27 +0,0 @@ -"""Parse constants from the config file and environment variables.""" - -from os import environ -from typing import Union -from configparser import ConfigParser - - -config = ConfigParser() -config.read('config.ini') - - -def get_constant( - env_name: str, config_header: str, config_key: str -) -> Union[str, int]: - """Get a constant from the environment or config.""" - constant = environ.get(env_name) or config.get(config_header, config_key) - if constant.isnumeric(): - constant = int(constant) - return constant - - -LOCAL_PORT = get_constant('LOCAL_PORT','flask', 'local_port') -GROUPME_ID = get_constant('GROUPME_ID', 'groupme', 'bot_id') -BOT_TOKEN = get_constant('DISCORD_BOT_TOKEN', 'discord', 'bot_token') -WEBHOOK_URL = get_constant('DISCORD_WEBHOOK', 'discord', 'webhook_url') -GROUPME_TOKEN = get_constant('GROUPME_TOKEN', 'groupme', 'access_token') -CHANNEL_NAME = get_constant('DISCORD_CHANNEL_NAME', 'discord', 'channel_name') diff --git a/credentials.py.sample b/credentials.py.sample new file mode 100644 index 0000000..e25f46c --- /dev/null +++ b/credentials.py.sample @@ -0,0 +1,15 @@ +#edit settings and copy this to credentials.py + +### SUPER SECRET ### +GROUPME_TOKEN="groupme token here" +BOT_TOKEN="discord bot token" +### SUPER SECRET END ### + +settings = [ + { + 'bot_id': "groupme_bot_id", + 'channel_name': "cs_memes", # discord + 'webhook_url': "discord_webhook_url", + 'local_port': 42069 # server internal port + } +] \ No newline at end of file diff --git a/main.py b/main.py index aa8fb43..a301f5c 100644 --- a/main.py +++ b/main.py @@ -2,28 +2,22 @@ import web_server import discord_bot +import time -from constants import BOT_TOKEN, GROUPME_TOKEN #set as environment variables +from credentials import * -settings = [ - { - 'bot_id': "60d8f6e70e5fe17ff5e236e072", #groupme - 'channel_name': "cs_memes", #discord - 'webhook_url': "https://discordapp.com/api/webhooks/730924768769081457/wB3rLeUJKnUrfk4clQaaYJ2eVHGm6WhJa2lLICSerHvBl4fYFmYhShaligTWknbK-h88", - 'local_port': 50070 #server - } -] -for instance in settings: - GROUPME_ID=instance['bot_id'] - CHANNEL_NAME=instance['channel_name'] - WEBHOOK_URL=instance['webhook_url'] - LOCAL_PORT=instance['local_port'] +for instance in settings: + GROUPME_ID = instance['bot_id'] + CHANNEL_NAME = instance['channel_name'] + WEBHOOK_URL = instance['webhook_url'] + LOCAL_PORT = instance['local_port'] flask_options = {} - if "false" in str(LOCAL_PORT): - flask_options = {'host': '0.0.0.0', port: LOCAL_PORT} + if "false" not in str(LOCAL_PORT): + flask_options = {'host': '127.0.0.1', 'port': LOCAL_PORT} discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) web_server.main(WEBHOOK_URL, **flask_options) + time.sleep(2) From 346972ed88bac3a3c87bcf24350cddb90f3fe349 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Fri, 10 Jul 2020 12:45:46 -0400 Subject: [PATCH 13/14] possible custom groupme tokens for each instance --- main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a301f5c..42f7a88 100644 --- a/main.py +++ b/main.py @@ -13,11 +13,16 @@ WEBHOOK_URL = instance['webhook_url'] LOCAL_PORT = instance['local_port'] + try: + gm_token=instance['groupme_token'] + except KeyError: + gm_token=GROUPME_TOKEN + flask_options = {} if "false" not in str(LOCAL_PORT): flask_options = {'host': '127.0.0.1', 'port': LOCAL_PORT} - discord_bot.main(BOT_TOKEN, GROUPME_TOKEN, GROUPME_ID, CHANNEL_NAME) + discord_bot.main(BOT_TOKEN, gm_token, GROUPME_ID, CHANNEL_NAME) web_server.main(WEBHOOK_URL, **flask_options) - time.sleep(2) + time.sleep(1) From b9e33cf13941fd3ec0ceb0d4c77d5f410a49c6fb Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra <32671690+karmanyaahm@users.noreply.github.com> Date: Mon, 21 Feb 2022 16:53:55 -0500 Subject: [PATCH 14/14] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a4f4dac..524e6e8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # GroupMeDiscord +This fork is deprecated by a rewritten version of this written in Go to make it easier to deploy and it just works better for me personally. https://github.com/karmanyaahm/groupme_discord_bridge_v3 + +--- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f75c31c547204176a8e8dc4412918b17)](https://app.codacy.com/app/AnonGuy/GroupMeDiscord?utm_source=github.com&utm_medium=referral&utm_content=AnonGuy/GroupMeDiscord&utm_campaign=Badge_Grade_Dashboard) [![Build Status](https://travis-ci.org/AnonGuy/GroupMeDiscord.svg?branch=master)](https://travis-ci.org/AnonGuy/GroupMeDiscord) [![Updates](https://pyup.io/repos/github/AnonGuy/GroupMeDiscord/shield.svg)](https://pyup.io/repos/github/AnonGuy/GroupMeDiscord/)