feat(discord): add list channels data

This commit is contained in:
Ali BARIN
2022-10-30 22:28:16 +01:00
parent 9c40bc5863
commit 79e609e682
3 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
import listChannels from "./list-channels";
export default [
listChannels,
];

View File

@@ -0,0 +1,32 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List channels',
key: 'listChannels',
async run($: IGlobalVariable) {
const channels: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
const response = await $.http.get(`/guilds/${$.auth.data.guildId}/channels`);
channels.data = response.data
.filter((channel: IJSONObject) => {
// filter in text channels only
return channel.type === 0;
})
.map((channel: IJSONObject) => {
return {
value: channel.id,
name: channel.name,
};
});
return channels;
},
};

View File

@@ -1,6 +1,7 @@
import defineApp from '../../helpers/define-app'; import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header'; import addAuthHeader from './common/add-auth-header';
import auth from './auth'; import auth from './auth';
import data from './data';
import actions from './actions'; import actions from './actions';
import triggers from './triggers'; import triggers from './triggers';
@@ -15,6 +16,7 @@ export default defineApp({
primaryColor: '5865f2', primaryColor: '5865f2',
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
data,
triggers, triggers,
actions, actions,
}); });