tyler569 icon

mimicbot

tyler569 | PRO | 10/01/17 07:48:08 PM UTC | 0 ⭐ | 911 👁️ | Never ⏰ | []
CoffeeScript |

1.25 KB

|

None

|

0 👍

/

0 👎

 
irc = require('irc')
 
client = new irc.Client(
    'irc.openredstone.org',
    'mimicbot',
    {
        channels: ['#openredstone'],
        userName: 'tbot8',
        realName: 'The 8th tbot'
    }
)
 
graph = {}
 
client.addListener('message', (from, to, msg) ->
    console.log(from, '->', to, ':', msg)
 
    if to == 'tbot8'
        return
 
    if msg.match /~mimic/
        sentence = [randomKey graph]
        last = sentence[0]
        while graph[last]
            last = (randomElem(graph[last]))
            sentence.push(last)
            if sentence.length > 15 then break
        client.say('#openredstone', sentence.join(' '))
 
        return
 
 
 
    if from.match /ORE/
        chat = msg.substr((msg.indexOf ':') + 2)
    else
        chat = msg
 
    chat = chat.split(' ')
    if chat.length <= 1 then return
 
    for i in [0 .. chat.length - 2]
        if graph[chat[i]]
            graph[chat[i]].push(chat[i + 1])
        else
            graph[chat[i]] = [ chat[i + 1] ]
 
    console.log(graph)
)
 
randomElem = (arr) ->
    arr[Math.floor(Math.random() * arr.length)]
 
randomKey = (obj) ->
    randomElem Object.keys(obj)
 
 
 
setTimeout(() ->
    client.say('NickServ', 'identify orepassword')
, 1500)

Comments