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

update #1

Merged
merged 21 commits into from
Aug 2, 2018
Merged
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ typings/
.vscode

./config/dev.json

db/**
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
LOKI_DB_PATH=
```

## Commands available

- help
- doc
- feedtweeter
- subscribe [list]
- unsubscribe
- alert
2 changes: 1 addition & 1 deletion config/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
"StrongLoop",
"JSKongress"
]
}
}
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ const CommandManager = require('./src/command')
const TwitterPlugin = require('./src/plugin/twitter')
const docCmd = require('./src/commands/doc')
const helpCmd = require('./src/commands/help')
const subscriberCmd = require('./src/commands/subscriber')
const welcomeEmbed = require('./src/embeds/welcome')
const joinLeftEmbed = require('./src/embeds/join-left')

const CM = CommandManager.init()
CM.addCommand('doc', docCmd)
CM.addCommand('help', helpCmd)
CM.addCommand('subscribe', subscriberCmd.subscribe)
CM.addCommand('sub', subscriberCmd.subscribe)
CM.addCommand('unsubscribe', subscriberCmd.unsubscribe)
CM.addCommand('unsub', subscriberCmd.unsubscribe)
CM.addCommand('alert', subscriberCmd.alert)

const RM = new Event()

const ESBot = new Discord.Client()

ESBot.on('ready', () => {
ESBot.once('ready', () => {
TwitterPlugin.init(ESBot.channels.find('name', 'tweets'))

console.log('ES Bot up and ready')
Expand Down
11 changes: 8 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@sindresorhus/is": "^0.9.0",
"discord.js": "^11.3.2",
"lokijs": "^1.5.5",
"twit": "^2.2.9"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ const CommandManager = require('../command')

module.exports = ({ message }) => {
const commands = [...CommandManager.i.getRegisteredCommands()]
message.channel.send(`All commands available are:\n!${commands.join('\n!')}`)
message.author.send(`Commandes disponibles : \n!${commands.join('\n!')}`)
return message.delete()
}
88 changes: 88 additions & 0 deletions src/commands/subscriber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const Loki = require('lokijs')

const dbPath = process.env.LOKI_DB_PATH

const db = new Loki(dbPath, {
autoload: true,
autosave: true,
autoloadCallback: () => {
subs = db.getCollection('subscribers')
if (subs === null) subs = db.addCollection('subscribers')
}
})

let subs = null

module.exports.subscribe = ({
message,
args
}) => {
if (args.length === 0) {
const subscribedChannel = subs.findOne({
userId: message.author.id,
channel: message.channel.name
})
if (subscribedChannel !== null) {
message.author.send(`Vous êtes déjà abonné au channel \`#${message.channel.name}\``)
return message.delete()
}
subs.insert({
userId: message.author.id,
channel: message.channel.name
})
message.author.send(`Vous vous êtes abonné au channel \`#${message.channel.name}\``)
return message.delete()
}
if (args[0] === 'list') {
const subscribedChannels = subs.find({
userId: message.author.id
})
if (subscribedChannels.length === 0) {
message.author.send(`Vous n'êtes abonné à aucun channel`)
return message.delete()
}
message.author.send(`Vous êtes abonnés aux channels suivants :\n${subscribedChannels.map(a => `\`#${a.channel}\``).join('\n')}`)
return message.delete()
}
}

module.exports.unsubscribe = ({
message,
args
}) => {
if (args.length === 0) {
const subscribedChannel = subs.findOne({
userId: message.author.id,
channel: message.channel.name
})
if (subscribedChannel !== null) {
subs.remove(subscribedChannel)
message.author.send(`Vous vous êtes désabonné au channel \`#${message.channel.name}\``)
return message.delete()
}
message.author.send(`Vous n'êtes pas abonné au channel \`#${message.channel.name}\``)
return message.delete()
}
}

module.exports.alert = ({
message,
args
}) => {
if (!message.member.roles.find("name", "Mentor")) {
return message.delete()
}
if (args.length === 0) {
message.author.send(`Veuillez mettre un message à votre alert : \`!alert <message>\` `)
return message.delete()
}
const subscribersOnChannel = subs.find({
channel: message.channel.name
})
if (subscribersOnChannel.length === 0) {
message.channel.send(`${args.join(' ')}\nIl n'y a pas d'abonné à ce channel...`)
return message.delete()
}
message.channel.send(`${args.join(' ')}\n${subscribersOnChannel.map(sub => `<@${sub.userId}>`).join(', ')}`)
return message.delete()
}