Skip to content

Commit

Permalink
Merge pull request #82 from Project-Coda/dev
Browse files Browse the repository at this point in the history
Add Welcome Messages
  • Loading branch information
ikifar2012 authored Nov 22, 2022
2 parents 43355e9 + b15e182 commit 35745cb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ global.client.on('guildMemberAdd', async member => {
}
}
greet.sendNotify(member);
greet.sendWelcome(member);
// Update presence
const guild = global.client.guilds.cache.get(env.discord.guild);
const members = await guild.members.fetch();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coda-utilities",
"version": "2.1.0",
"version": "2.2.0",
"description": "A general utilities bot for Coda",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion utilities/greet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mariadb = require('../db.js');
const env = require('../env.js');
const embedcreator = require('../embed.js');
const welcome = require('./welcome.js');
// get users from database and put id's in array
async function getUsers() {
db = await mariadb.getConnection();
Expand Down Expand Up @@ -109,5 +110,16 @@ async function SendNewBotAlert(member) {
);
}

async function sendWelcome(member) {
// send welcome message
const welcome_channel = await global.client.channels.cache.get(env.discord.welcome_channel);
const welcome_message = await welcome.getWelcome();
welcome_channel.send(
// send message
{
content: 'Welcome to ' + global.client.guilds.cache.get(env.discord.guild).name + `${member.user}` + '!\n' + await welcome_message,
},
);
}

module.exports = { sendNotify, getUsers, sendKickAlert, SendNewBotAlert };
module.exports = { sendNotify, getUsers, sendKickAlert, SendNewBotAlert, sendWelcome };
16 changes: 16 additions & 0 deletions utilities/welcome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const env = require('../env.js');
const fetch = require('node-fetch');
async function getList() {
file = await fetch(env.utilities.welcomemessagesfile);
messages = await file.text();
messages = messages.split(' end');
return messages;
}

async function getWelcome() {
const welcomelist = await getList();
const welcome = welcomelist[Math.floor(Math.random() * (welcomelist.length - 1))];
return welcome.replace(/\\n/g, '\n');
}

module.exports = { getList, getWelcome };

0 comments on commit 35745cb

Please sign in to comment.