-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToDc_DcBot.py
67 lines (51 loc) · 1.6 KB
/
ToDc_DcBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Sends messages into the dc
import json
import os
import discord
from discord.ext import commands
import asyncio
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
signal_running = True
telegram_running = True
with open("config_own.json", "r") as read_file:
data = json.load(read_file)
sendChannelID = data["discord"]["SignalDiscordChatId"]
@bot.command()
async def myloop_signal(ctx):
old_text = ""
while signal_running:
print("Loop running")
with open("messageCarrierFromSignal.txt") as file:
text = file.read()
print(f"current text = {text}")
new_text = text
if new_text != old_text:
print(f"sending: {text}")
await send_message(sendChannelID, text)
old_text = new_text
await asyncio.sleep(1)
@bot.command()
async def myloop_telegram(ctx):
old_text = ""
while telegram_running:
print("Loop running")
with open("messageCarrierFromTelegram.txt") as file:
text = file.read()
print(f"current text = {text}")
new_text = text
if new_text != old_text:
print(f"sending: {text}")
await send_message(sendChannelID, text)
old_text = new_text
await asyncio.sleep(1)
async def send_message(channel_id, message):
await bot.get_channel(channel_id).send(message)
@bot.event
async def on_ready():
print('Bot is ready.')
# await myloop_signal()
# await myloop_telegram()
def run_bot():
bot.run(data["discord"]["SignalToDc_BotToken"])
if __name__ == '__main__':
run_bot()