Skip to content

Commit

Permalink
fix(web): update web code for discord v12
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Apr 8, 2020
1 parent 98444c8 commit d58b62b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
43 changes: 23 additions & 20 deletions lib/Web.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,29 @@ app.post('/', async (req, res) => {
};
const branch = data.ref ? GetBranchName(data.ref) : data.object_attributes.ref;

channels.forEach((conf) => {
const wantsEmbed = conf.get('useEmbed');
const channel = bot.channels.get(conf.id);

if (!channel) return;

if (
!filter[conf.get('eventsType')](conf.get('eventsList'))(eventName + actionText) ||
!filter[conf.get('usersType')](conf.get('usersList'))(actor.name) ||
!filter[conf.get('branchesType')](conf.get('branchesList'))(branch)
) {
return;
}

if (wantsEmbed) {
channel.send({ embed: eventResponse.embed }).catch((err) => handleError(err, channel));
} else {
channel.send(`**${repo}**: ${eventResponse.text}`).catch((err) => handleError(err, channel));
}
});
Promise.allSettled(
channels.map(async (conf) => {
const wantsEmbed = conf.get('useEmbed');
const channel = await bot.channels.fetch(conf.id);

if (!channel) return;

if (
!filter[conf.get('eventsType')](conf.get('eventsList'))(eventName + actionText) ||
!filter[conf.get('usersType')](conf.get('usersList'))(actor.name) ||
!filter[conf.get('branchesType')](conf.get('branchesList'))(branch)
) {
return;
}

try {
if (wantsEmbed) await channel.send({ embed: eventResponse.embed });
else await channel.send(`**${repo}**: ${eventResponse.text}`);
} catch (err) {
handleError(err, channel);
}
})
);
});

app.use(
Expand Down
2 changes: 1 addition & 1 deletion views/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</h1>
<br>
<h2 class="subtitle is-4 description">
It's time to say hello to Gitlab repo events right in your Discord server. <br>
It's time to say hello to GitLab repo events right in your Discord server. <br>
Simply set up webhooks to a server, init repo in channel, and you're good-to-go!
</h2>
<br>
Expand Down
2 changes: 1 addition & 1 deletion views/layout.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<div class="container">
<div class="tabs is-centered">
<ul>
<li><a href="https://datitisev.me" target="_blank">Copyright © 2019 David Sevilla Martin</a></li>
<li><a href="https://datitisev.me" target="_blank">Copyright © 2020 David Sevilla Martin</a></li>
<li><a href="http://bulma.io" target="_blank">Made with Bulma</a></li>
<li><a href="http://discordapp.com" target="_blank">Made for Discord</a></li>
</ul>
Expand Down

0 comments on commit d58b62b

Please sign in to comment.