Skip to content

Instantly share code, notes, and snippets.

@Artoria2e5
Last active February 8, 2016 10:13
Show Gist options
  • Save Artoria2e5/6d02c7c9b872aabca4c4 to your computer and use it in GitHub Desktop.
Save Artoria2e5/6d02c7c9b872aabca4c4 to your computer and use it in GitHub Desktop.
tg2ircbot
exports = {
// not impl'ing tg multiacc now
telegram: {
// apikey: botcfg
'foobar': {
groups: {
// grpid : grpcfg
'23333': {
outfilter: (s) => s.replace('nangcr','南瓜超人'),
infilter : (s) => s.replace('phoenixlzx', '[who must not be named]')
}
}
}
},
irc: {
'irc.freenode.net:6697': {
sasl: false,
ssl: true,
ssl_self_signed: false,
// bridge-bot conf may be global.
bridges: ['toxsync', 'MGTBot'],
maxlines: 5,
maxlen: 300,
pastbin_oversided: false, // todo make this configurable
fwdimg: true,
fwdstk: true,
username: 'meow',
channels: {
'#archlinux-cn': {
maxlines: 10, // archers are more H2O
maxlen: 500, // same
fwdimg: false,// yellow pics too many no good
},
'#nyaacat': {
bridges: ['NyaaCat'] // +=
}
}
}
},
blocks: [
// basic fully-qualified name spec:
// fcname ::= protocol ':' serverName '#' channel
// replace any component with 'ALL' to match all subnodes of the tree
// for tg, serverName is apikey.
{ uid: '12345', from: 'tg:foobar#23333', to: 'irc:irc.freenode.net:6697#nyaacat' },
{ uid: 'varia', from: 'irc:irc.freenode.net##Orz', to: 'tg:foobar#23333' },
{ uid: 'smbot', from: 'irc:ALL', to: 'ALL' },
]
}
# https://github.com/wfjsw/telegram2irc-bot/blob/master/main.js
'use strict'
Telegram = require('node-telegram-bot-api')
IRC = require('irc')
Encoding = require('encoding')
config = require('./config.js')
pvimcn = require('./pvimcn.js')
nickmap = require('./nickmap.js')
tgClients = []
ircClients = []
# TODO:
for ii in config.irc:
scfg = config.irc[ii]
client = new IRC.Clinet ii, {
channels: [scfg.channels.keys()],
sasl: scfg.sasl,
ssl : scfg.ssl,
# etc, too lazy
}
ircHandlers += ii # for happy debugging and injection
IRCinfo[ii].channels.forEach (c) ->
listen message -> sayAll(dataChunk, ii + c)
listen action ....... actionAll...
# recv..
# match command, call command, ...
# else broadcast sayAll...
sayAll = (dataChunk, fullyQualifiedName) ->
sayHandlers.forEach hnd ->
hnd(textify(dataChunk)) if hnd.name !== fullyQualifiedName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment