forked from TediCross/TediCross
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
62 lines (48 loc) · 1.77 KB
/
main.js
File metadata and controls
62 lines (48 loc) · 1.77 KB
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
"use strict";
/**************************
* Import important stuff *
**************************/
// General stuff
const path = require("path");
const Application = require("./lib/Application");
const MessageMap = require("./lib/MessageMap");
const DiscordUserMap = require("./lib/discord2telegram/DiscordUserMap");
const Bridge = require("./lib/Bridge");
const BridgeMap = require("./lib/BridgeMap");
const Settings = require("./lib/Settings");
// Telegram stuff
const { BotAPI, InputFile } = require("teleapiwrapper");
const telegramSetup = require("./lib/telegram2discord/setup");
// Discord stuff
const Discord = require("discord.js");
const discordSetup = require("./lib/discord2telegram/setup");
/*************
* TediCross *
*************/
// Wrap everything in a try/catch to get a timestamp if a crash occurs
try {
// Get the settings
const settingsPath = path.join(__dirname, "settings.json");
const settings = Settings.fromFile(settingsPath);
// Save the settings
settings.toFile(settingsPath);
// Create/Load the discord user map
const dcUsers = new DiscordUserMap(path.join(__dirname, "data", "discord_users.json"));
// Create a message ID map
const messageMap = new MessageMap();
// Create the bridge map
const bridgeMap = new BridgeMap(settings.bridges.map((bridgeSettings) => new Bridge(bridgeSettings)));
// Create a Telegram bot
const tgBot = new BotAPI(settings.telegramToken);
// Create a Discord bot
const dcBot = new Discord.Client();
/*********************
* Set up the bridge *
*********************/
discordSetup(dcBot, tgBot, dcUsers, messageMap, bridgeMap, settings);
telegramSetup(tgBot, dcBot, dcUsers, messageMap, bridgeMap, settings);
} catch (err) {
// Log the timestamp and re-throw the error
Application.logger.error(err);
throw err;
}