Skip to content

Commit

Permalink
Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
uninhm committed Jun 19, 2020
1 parent c978cee commit bbd414a
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/bot_irc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import irc, strutils, telebot, strformat, asyncdispatch, options, parsecfg

let config = loadConfig("config.ini")

#[
var
TELEGRAM_TOKEN: string
IRC : string
IRC_NICK : string
IRC_PASS : string
IRC_CHANNEL {.threadvar.}: string
TG_GROUP_ID {.threadvar.}: int

IRC_CHANNEL : string
TG_GROUP_ID : int
]#

# Puro strip, mejor prevenir que lamentar
TG_GROUP_ID = config.getSectionValue("Telegram", "group_id").strip.parseInt
TELEGRAM_TOKEN = config.getSectionValue("Telegram", "token").strip
let
TG_GROUP_ID = config.getSectionValue("Telegram", "group_id").strip.parseInt
TELEGRAM_TOKEN = config.getSectionValue("Telegram", "token").strip

IRC = config.getSectionValue("IRC", "irc").strip
IRC_NICK = config.getSectionValue("IRC", "nick").strip
IRC_CHANNEL = config.getSectionValue("IRC", "channel").strip
IRC_PASS = config.getSectionValue("IRC", "pass").strip
IRC = config.getSectionValue("IRC", "irc").strip
IRC_NICK = config.getSectionValue("IRC", "nick").strip
IRC_CHANNEL = config.getSectionValue("IRC", "channel").strip
IRC_PASS = config.getSectionValue("IRC", "pass").strip


# ------ Code ------

var bot {.threadvar.}: TeleBot
bot = newTeleBot(TELEGRAM_TOKEN)
let bot = newTeleBot(TELEGRAM_TOKEN)


proc onIrcEvent(client: AsyncIrc, event: IrcEvent) {.async.} =
Expand All @@ -39,21 +40,22 @@ proc onIrcEvent(client: AsyncIrc, event: IrcEvent) {.async.} =
if event.cmd == MPrivMsg:
var msg = event.params[event.params.high]
let text = fmt"*{event.nick}*: {msg}"
discard await bot.sendMessage(TG_GROUP_ID, text, parseMode = "markdown")
{.gcsafe.}:
discard await bot.sendMessage(TG_GROUP_ID, text, parseMode = "markdown")

var client {.threadvar.}: AsyncIrc
client = newAsyncIrc(IRC, nick = IRC_NICK,
joinChans = @[IRC_CHANNEL],
serverPass = IRC_PASS,
callback = onIrcEvent)
let client = newAsyncIrc(IRC, nick = IRC_NICK,
joinChans = @[IRC_CHANNEL],
serverPass = IRC_PASS,
callback = onIrcEvent)

proc updateHandler(b: Telebot, u: Update): Future[bool] {.async.} =
if not u.message:
return true
var m = u.message.get
if m.text and m.chat.id == TG_GROUP_ID:
await client.privmsg(IRC_CHANNEL,
fmt"{m.fromUser.get.firstName}: {m.text.get}")
{.gcsafe.}:
await client.privmsg(IRC_CHANNEL,
fmt"{m.fromUser.get.firstName}: {m.text.get}")


bot.onUpdate(updateHandler)
Expand Down

0 comments on commit bbd414a

Please sign in to comment.