Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Allow multiple chats from one instance #20

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
credentials.py
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)


Expand Down
11 changes: 0 additions & 11 deletions config.ini

This file was deleted.

27 changes: 0 additions & 27 deletions constants.py

This file was deleted.

15 changes: 15 additions & 0 deletions credentials.py.sample
Original file line number Diff line number Diff line change
@@ -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
}
]
9 changes: 5 additions & 4 deletions discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,channelName

"""Start the bot with the provided token."""
Process(target=bot.run, args=(BOT_TOKEN,)).start()
25 changes: 19 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

import web_server
import discord_bot
import time

from constants import RUN_LOCAL
from credentials import *


flask_options = {}
for instance in settings:
GROUPME_ID = instance['bot_id']
CHANNEL_NAME = instance['channel_name']
WEBHOOK_URL = instance['webhook_url']
LOCAL_PORT = instance['local_port']

if not RUN_LOCAL:
flask_options = {'host': '0.0.0.0'}
try:
gm_token=instance['groupme_token']
except KeyError:
gm_token=GROUPME_TOKEN

discord_bot.main()
web_server.main(**flask_options)
flask_options = {}

if "false" not in str(LOCAL_PORT):
flask_options = {'host': '127.0.0.1', 'port': LOCAL_PORT}

discord_bot.main(BOT_TOKEN, gm_token, GROUPME_ID, CHANNEL_NAME)
web_server.main(WEBHOOK_URL, **flask_options)
time.sleep(1)
5 changes: 3 additions & 2 deletions web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import requests
from flask import Flask, request

from constants import WEBHOOK_URL


app = Flask(__name__)
Expand All @@ -26,6 +25,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()