1.0.1 • Published 6 years ago

discord_telephone v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

#Telephone - A discord.js addon

This module is a discord.js addon that connects two guilds and allows their members to talk to each other in a very simple way.

##Simple Usage

const Telephone = require('telephone');
 
 if (message.content.startsWith(`#kk`)) {
        const Line = new Telephone({client: client, guild: message.guild, linename: 'thing', channelName: 'tele'})
        const ons = {
            whenDone: function(callerchannel, listenerchannel) {
                callerchannel.send(`Connected to guild: ${listenerchannel.guild.name}!`);
                listenerchannel.send(`Connected to guild: ${callerchannel.guild.name}!`);
            },
            onBegin: function(channel, guild) { channel.send(`${guild.name} wants a call!`)},
            onFind: function(user) { message.channel.send(`User found!: ${user.username}`) },
            onNoFind: function() { message.channel.send('No one picked up! :(')},
             onEnd: function(messages) {message.channel.send(`Call ended! Message history:\n${messages.map(message => `**${message.author.username}:** ${message.content}`).join('\n')}`)},
             onMessageCaller: function(element, channel) { if (element.content == 'stop') return Line.Stop(); channel.send(`${element.author.username}: ${element.content}`) },
             onMessageCallee: function(element, channel) { channel.send(`${element.author.username}: ${element.content}`)}
        }
        await Line.requestGuild(ons.whenDone, ons);
        //const listener = Line.requestUser({time: 100000, filter: msg => msg.author.bot == false}, ons);
        await Line.Start({time: 60000, filter: msg => msg.author.bot == false}, ons);
    }

#Documentation

##Legend caller and callee caller is the user / guild you specify when creating the Line instance. Callee is the user / guild the caller is talking to.

options => The message collector options. filter and time - Both always required.

ons => Functions to be executed when something happens.

  • whenDone(callerchannel, calleechannel) => required parameter of requestGuild
  • onBegin(calleechannel, callerguild) => optional parameter of requestCallee
  • onFind(calleeuser) => optional parameter of requestCallee
  • onNoFind() => optional parameter of requestCallee
  • onMessageCaller(element, CalleeChannel) => required parameter of Start
  • onMessageCallee(element, CallerChannel) => required parameter of Start
  • onEnd(messages) => optional parameter of Start

##Classes and methods

* [Line](##Line) ⇒ <code>Telephone</code>
   * [.requestGuild(whenDone, options)](###.requestGuild) ⇒ returns `CalleeChannel`
   * [.requestCallee(options, ons)](###.requestCallee) ⇒ returns `CalleeUser`
   * [.Start(options, ons)](###.Start) ⇒ returns `Promise`
   * [.Stop()](###.Stop) ⇒ returns `Void`

##Line

Creates a Telephone instance.

Everything must be inside an object, position doesn't matter. The Params ARE case-sensitive. | Param | Type | Description | | --- | --- | --- | | client | D.JS Client | Your discord.js client. Required | | guild | D.JS Guild | The caller guild. Required | | linename | String | The name of the line instance. Required | | channelName | String | In which channel should the bot listen for messages. Note: Both the caller and callee guild need to have a channel that is named this. Required |

###.requestGuild

Gets one of the bot's guilds and makes it the callee guild. Can be random or targeted. Note that this method is required in order for the connection to work.

ParamTypeDescription
whenDoneFunctionWhat should happen when the bot finds the guild. Required
options = {Target: ... }ObjectThe targeted guild. Optional. If not specified it will be random

###.requestCallee

This method gets the first user who sends a message and meets the filter. This method is not required for a connection to work.

ParamTypeDescription
optionsObjectThe filter and time of the message collector. Required
onsObjectAll optional on functions. Optional

###.Start

Begins the Caller Callee connection. Required in order for the connection to work.

ParamTypeDescription
optionsObjectThe filter and time of the message collector. Required
onsObjectAll optional on functions, and the required onEnd function.

###.Stop

Stops the connections and triggers the onEnd event.


#Need help and/or examples?

Then please check out this module's github page, and if there is a problem / suggestion / help needed please submit an issue!. If you like this module then please star it <3!