Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to core functionality #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
token.json
.env
node_modules/
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# *Call of Duty: Mobile Luxembourg* Discord Bot
# Dev Bot

Custom Discord Bot for the **Call of Duty: Mobile Luxembourg** Discord Server \
Used primarily for experimentation / learning and for fun
Custom Discord Bot for experimentation, learning and fun.

## Hosting the bot
The bot is currently not doing anything because it is not actively hosted.

If you wish to host the bot, you are welcome to open an issue with your contact info and a team member will send you the discord auth token. From there on, simply clone this github repository and add `token.json`:
``` json
// token.json
{
"token": "PASTE_TOKEN_HERE"
}
```
If you wish to run the bot, follow these steps:
1. Clone this github repository
2. Install npm dependencies (`npm i`)
3. Add your bot auth token in `.env`:
``` js
// .env
AUTH_TOKEN=gnd87hmp45hs5qyss4p2p87s2mppgsp2gs4p2a7gfmp
// obviously, this is not a valid token - replace it with your own
```
192 changes: 98 additions & 94 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,118 @@
// formatting
const { stripIndent } = require('common-tags')
const { roles, channels } = require('./config.json');

// stores API keys in separate JSON file
const { token } = require('./token.json');

// require the discord.js module
// create a new Discord bot session
const Discord = require('discord.js');

// create a new Discord client
const bot = new Discord.Client();

// auth
bot.login(token);

// when the client is ready, run this code
// this event will only trigger one time after logging in
bot.once('ready', () => {
console.log(stripIndent`
--- Bot online ---
`);
require('dotenv').config();
bot.login(process.env.AUTH_TOKEN);

// this event will only trigger once: on bot init
bot.on('ready', () => {
console.log('\x1b[32m%s\x1b[0m', "--- Bot online ---");
const args = process.argv.slice(2);
if (args[0] == "announce") {
bot.channels.cache.get(channels.bots).send("Hello there! I'm back online");
}
});

// new member welcome
bot.on('guildMemberAdd', member => {
console.log(member)
member.guild.channels.cache.get('704743628572196927').send(`:wave: Welcome, <@${member.id}> to **${member.guild.name}**\nDon't forget to check out our ${member.guild.rulesChannel} channel and set your nickname to your CoDM player tag!`);
console.log(`${member} joined the server`)
member.guild.channels.cache.get(channels.welcome).send(`:wave: Welcome, <@${member.id}> to **${member.guild.name}** :wave:`);
});

// interactive functionality
bot.on('message', message => {
console.log(message.author.username, ":", message.content)
// for testing only: console.log(message.author.username, ":", message.content)

const args = message.content.toLowerCase().trim().split(' ');

// for fun
if (args[0] == 'happy') {
message.react('😄');
}
if (args[0] == 'sad') {
message.react('😢');
}

// Reply with server welcome
if (args[0] == 'server-welcome') {
const welcome = new Discord.MessageEmbed()
.setTitle('Hello and welcome to **Call of Duty: Mobile Luxembourg**')
.setDescription("We're a community server for CoD:M players based in Luxembourg, but are also open to all other EU West players")
.addFields(
{ name: '__Server Invite Link:__', value: '[https://discord.gg/uuagJHE](https://discord.gg/uuagJHE)' },
{ name: '__General Information:__', value: "**Server Region:** Your CoDM Server Region should be Western Europe (EU West)\n**Time Zone:** Default time zone is CEST, when communicating time mention the time zone if it is any other.\n**Languages:** Primary language is Luxembourgish, but since we're all gamers, English is of course equally fine. French and German are welcome too."},
{ name: '__Rules:__', value: '**Read the [official discord rules and guidelines](https://discordapp.com/guidelines)**\n**Naming:** Your name has to match your CoD:M player name (case-sensitive). If this is not the case, change your server nickname'},
{ name: '__Contributing:__', value: '**Join our [Github organisation](https://github.com/lux-gaming)**\n**Contribute to our [homegrown bot](https://github.com/lux-gaming/codm-lu-bot)**'},
)
.setTimestamp()
message.channel.send(welcome);
}

// Lists all affiliated servers
if (args[0] == 'affiliate-servers') {
const codmservers = new Discord.MessageEmbed()
.setTitle('Official Call of Duty: Mobile Discord Servers')
.setDescription('Join our official codm partner servers')
.addFields(
{ name: 'Global Servers', value: '[TiMi](https://discord.gg/codm)\n[The Other](https://discord.gg/callofdutymobile)' },
{ name: 'EU Servers', value: '[:flag_lu: Luxembourg](https://discord.gg/uuagJHE)\n[:flag_de: Germany](https://discord.gg/JE65Bcf)\n[:flag_fr: France](https://discord.gg/SeQ6zmE)\n[:flag_it: Italy](https://discord.gg/g7yMEya)\n[:flag_es: Spain](https://discord.gg/EFcS6pn)'},
)
.setTimestamp()
message.channel.send(codmservers);

const luxservers = new Discord.MessageEmbed()
.setTitle('Cool Luxembourg Discord Servers')
.addFields(
{ name: 'Gaming', value: '[E-Sports.lu](https://discord.gg/GUNyB36)\n[Lux Gaming Corner](https://discord.gg/7SjtxVr)' },
{ name: 'Other', value: '[Gregorys shitty but sort of ok server](https://discord.gg/GEbmwVj)'},
)
.setTimestamp()
message.channel.send(luxservers);
}

// simple info commands
if (args[0] == 'server-info') {
message.channel.send(stripIndent`
----- **${message.guild.name}** -----

Founded: ${message.guild.createdAt}
Region: ${message.guild.region}

Owner: ${message.guild.owner}
Members: ${message.guild.memberCount}

Rules: ${message.guild.rulesChannel}
`);
}
else if (args[0] == 'user-info') {
return message.reply(`your username is ${message.author.username} and your user ID is ${message.author.id}`);
}

// easily delete multiple messages
if (args[0] == 'prune') {
if (message.member.roles.cache.has('745745452934103072')) {
message.channel.bulkDelete(parseInt(args[1]) + 1);
}
else {
return message.reply(`(${message.author.username}), only moderators are permitted to use this command`)
}
const command = args.shift();
console.log(command, args);

switch (command) {
case 'happy':
message.react('😄');
break;
case 'sad':
message.react('😢');
break;
case 'count':
switch (args[0]) {
case 'from':
if (args[1] != undefined) {
if (args[1] <= 10 ) {
message.channel.send("I'm counting ...");
for ( var i = args[1] ; i > 0 ; i-- ) {
message.channel.send(i);
}
message.channel.send("Done");
}
else {
message.channel.send("Please refrain from spamming");
}
} else {
message.channel.send("From what number would you like me to count down?");
}
break;
case 'to':
if (args[1] != undefined) {
if (args[1] <= 10 ) {
message.channel.send("I'm counting ...");
for ( var i = 1 ; i <= args[1] ; i++ ) {
message.channel.send(i);
}
message.channel.send("Done");
}
else {
message.channel.send("Please refrain from spamming");
}
}
else {
message.channel.send("Until what number would you like me to count?");
}
break;
default:
message.channel.send("How would you like me to count?");
}
break;
case 'welcome':
const welcome = new Discord.MessageEmbed()
.setTitle(`Hello and welcome to the **${message.guild.name}**`)
.setDescription("We're a community of devs")
.addFields(
{ name: 'Server Invite Link', value: '[https://discord.gg/https://discord.gg/DKKkJYj8hu](https://discord.gg/https://discord.gg/DKKkJYj8hu)' },
{ name: 'Rules', value: '**Read the [official discord rules and guidelines](https://discordapp.com/guidelines)**'},
{ name: 'Contributing', value: '**Contribute to our [homegrown bot](https://github.com/nico-bachner/dev-bot)**'}
)
.setTimestamp()
message.channel.send(welcome);
break;
case 'info':
switch(args[0]) {
case 'server':
message.channel.send(
new Discord.MessageEmbed()
.setTitle(`**${message.guild.name}**`)
.addFields(
{ name: 'Founded', value: message.guild.createdAt },
{ name: 'Region', value: message.guild.region },
{ name: 'Owner', value: message.guild.owner },
{ name: 'Members', value: message.guild.memberCount },
{ name: 'Rules', value: message.guild.rulesChannel }
)
.setTimestamp()
);
break;
case 'user':
return message.reply(`your username is ${message.author.username} and your user ID is ${message.author.id}`);
default:
message.channel.send("On which subject doth thee seek knowledge?");
}
}
});

// Automatically reconnect if the bot disconnects due to inactivity
bot.on('disconnect', function(erMsg, code) {
console.log('|----- Bot disconnected from Discord with code', code, 'for reason:', erMsg, '-----|');
console.log('\x1b[31m%s\x1b[0m', `--- Bot disconnected from Discord with code ${code} for the following reason: ${erMsg} ---`);
bot.connect();
});
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"roles": {
"moderator": "714583836138405980"
},
"channels": {
"welcome": "704743628572196927",
"bots": "730552046092157080"
}
}
Loading