-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkbot.js
More file actions
63 lines (52 loc) · 1.67 KB
/
linkbot.js
File metadata and controls
63 lines (52 loc) · 1.67 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
63
const Discord = require( 'discord.js' )
const bot = new Discord.Client()
const fs = require( 'fs' )
require('log-timestamp')
const general_chat = '291751672106188800'
const lobby_links = '743870766642233354'
const unified_link = new RegExp("^[a-z0-9]{3}-[a-z0-9]{4}$", "i")
function isGeneralChatChannel( channel ) {
return channel.id == general_chat
}
function isLobbyLinksChannel( channel ) {
return channel.id == lobby_links
}
bot.once('ready', async() => {
console.log( 'Link Bot ready' )
})
bot.on('message', async ( message ) => {
let inGenChat = isGeneralChatChannel( message.channel )
let inLobbyLinks = isLobbyLinksChannel( message.channel )
if ( !inGenChat && !inLobbyLinks ) return
if ( message.author.bot ) return
let content = message.content
let words = content.split(' ')
if ( inGenChat ) {
for ( const word of words ) {
if ( word.startsWith( 'steam://joinlobby' ) || word.match( unified_link ) ) {
bot.channels.get(lobby_links).send('From ' + message.author + ':\n> ' + content)
message.delete()
return
}
}
}
else if ( inLobbyLinks ) {
for ( const word of words ) {
if ( word.startsWith( 'steam://joinlobby' ) || word.match( unified_link ) ) {
return
}
}
message.delete()
}
})
fs.readFile( '/home/codenaugh/bots/data/tokens.json', ( err, data ) => {
if ( err ) throw err;
const tokens = JSON.parse( data );
bot.login( tokens.link );
})
bot.on( "error", ( err ) => {
console.error( err )
})
process.on( "uncaughtException", ( err ) => {
console.error( err )
})