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

WIP: Setup discord bot #1

Open
wants to merge 2 commits into
base: main
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
39 changes: 39 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div align="center">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is weird here https://github.com/snapshot-labs/discord-bot/tree/setup-discord-bot
I see plain html 🙈 not sure why
Untitled 3

<img src="https://raw.githubusercontent.com/snapshot-labs/snapshot/develop/public/icon.svg" height="70" alt="Snapshot Logo">
<h1>Snapshot - Discord Bot</h1>
<strong>
This is a Discord Bot for Snapshot.
</strong>
</div>
<br>
<div align="center">
<img src="https://img.shields.io/github/commit-activity/w/snapshot-labs/snapshot-hub" alt="GitHub commit activity">
<a href="https://github.com/snapshot-labs/snapshot-hub/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22">
<img src="https://img.shields.io/github/issues/snapshot-labs/snapshot-hub/help wanted" alt="GitHub issues help wanted">
</a>
<a href="https://telegram.snapshot.org">
<img src="https://img.shields.io/badge/Telegram-white?logo=telegram" alt="Telegram">
</a>
<a href="https://discord.snapshot.org">
<img src="https://img.shields.io/discord/707079246388133940.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2" alt="Discord">
</a>
<a href="https://twitter.com/SnapshotLabs">
<img src="https://img.shields.io/twitter/follow/SnapshotLabs?label=SnapshotLabs&style=flat&logo=twitter&color=1DA1F2" alt="Twitter">
</a>
</div>


### Development

#### Install dependencies
```bash
yarn
```

#### Run locally
```bash
yarn dev
```

### License
[MIT](LICENSE).
26 changes: 26 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import express from 'express';
import { sendEventToDiscordSubscribers } from './client';
import pkg from '../package.json';

const router = express.Router();

router.get('/', async (req, res) => {
return res.json({
name: pkg.name,
version: pkg.version
});
});

router.post('/event-to-subscribers', async (req, res) => {
const event: string = req.body.event || '';
const proposalId: string = req.body.proposalId || '';

try {
await sendEventToDiscordSubscribers(event, proposalId);
return res.json({ success: true });
} catch (e) {
return res.json({ error: e });
}
});
Comment on lines +14 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zzuziak

  • We should make sure this route is used only by us.
  • snapshot-webhook sends a secret in the authentication header, Example:
  • Untitled 2
  • We can add a variable in .env and check if the header is equal or not (for development env can be empty)
  • For
const proposalId: string = req.body.proposalId || '';

In the event payload proposal id is proposal.id


export default router;
Loading