Fixes
This commit is contained in:
@@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize};
|
||||
use serenity::model::prelude::{GuildChannel, ChannelType};
|
||||
use siren::ServiceError;
|
||||
|
||||
use crate::{AppState, bot::commands::audio::{play::play_track, join}, db::guilds::InsertGuild};
|
||||
use crate::{AppState, bot::commands::audio::{play::play_track, join}, db::guilds::{InsertGuild, QueryGuild}};
|
||||
|
||||
#[get("/guilds")]
|
||||
async fn get_guilds(data: web::Data<Arc<AppState>>) -> HttpResponse {
|
||||
@@ -249,6 +249,34 @@ struct SetVolume {
|
||||
volume: String
|
||||
}
|
||||
|
||||
#[get("/{guild_id}/voice/volume")]
|
||||
async fn get_volume(path: web::Path<String>) -> HttpResponse {
|
||||
let guild_id = path.into_inner();
|
||||
let guild_id = match guild_id.parse::<u64>() {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
warn!("Could not parse guild id: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError {
|
||||
status: 422,
|
||||
message: err.to_string()
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
let volume = match QueryGuild::get(guild_id as i64) {
|
||||
Ok(guild) => guild.volume,
|
||||
Err(err) => {
|
||||
warn!("Could not get volume: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError {
|
||||
status: 422,
|
||||
message: err.to_string()
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
HttpResponse::Ok().json(volume)
|
||||
}
|
||||
|
||||
#[post("/{guild_id}/voice/volume")]
|
||||
async fn set_volume(path: web::Path<String>, volume: web::Json::<SetVolume>, data: web::Data<Arc<AppState>>) -> HttpResponse {
|
||||
let guild_id = path.into_inner();
|
||||
@@ -277,6 +305,34 @@ async fn set_volume(path: web::Path<String>, volume: web::Json::<SetVolume>, dat
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
#[post("/{guild_id}/voice/skip")]
|
||||
async fn skip(path: web::Path<String>, data: web::Data<Arc<AppState>>) -> HttpResponse {
|
||||
let guild_id = path.into_inner();
|
||||
let guild_id = match guild_id.parse::<u64>() {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
warn!("Could not parse guild id: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError {
|
||||
status: 422,
|
||||
message: err.to_string()
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(handler_lock) = data.songbird.get(guild_id) {
|
||||
let handler = handler_lock.lock().await;
|
||||
if let Err(err) = handler.queue().skip() {
|
||||
warn!("Could not skip track: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError {
|
||||
status: 422,
|
||||
message: err.to_string()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
pub fn init_routes(config: &mut web::ServiceConfig) {
|
||||
config
|
||||
.service(get_guilds)
|
||||
@@ -289,5 +345,7 @@ pub fn init_routes(config: &mut web::ServiceConfig) {
|
||||
.service(resume)
|
||||
.service(pause)
|
||||
.service(set_volume)
|
||||
.service(get_volume)
|
||||
.service(skip)
|
||||
);
|
||||
}
|
||||
0
service/src/dnd/mod.rs
Normal file
0
service/src/dnd/mod.rs
Normal file
@@ -18,6 +18,7 @@ use crate::bot::{commands::oai::GPTModel, handler::Handler};
|
||||
|
||||
use dotenv::dotenv;
|
||||
|
||||
mod dnd;
|
||||
mod bot;
|
||||
mod db;
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ export async function getTextChannels(guildId: number): Promise<GuildChannel[]>
|
||||
return response?.data || { data: [] };
|
||||
}
|
||||
|
||||
export async function sendMessage(guildId: number, channelId: number, message: string): Promise<void> {
|
||||
await postRequest(`guilds/${guildId}/text/${channelId}/message`, { message });
|
||||
}
|
||||
|
||||
export async function getVoiceChannels(guildId: number): Promise<GuildChannel[]> {
|
||||
const response = await getRequest(`guilds/${guildId}/voice`, {});
|
||||
return response?.data || { data: [] };
|
||||
@@ -35,3 +39,12 @@ export async function resumeTrack(guildId: number): Promise<void> {
|
||||
export async function setVolume(guildId: number, volume: number): Promise<void> {
|
||||
await postRequest(`guilds/${guildId}/voice/volume`, { volume: `${volume}` });
|
||||
}
|
||||
|
||||
export async function skipTrack(guildId: number): Promise<void> {
|
||||
await postRequest(`guilds/${guildId}/voice/skip`, {});
|
||||
}
|
||||
|
||||
export async function getVolume(guildId: number): Promise<number> {
|
||||
const response = await getRequest(`guilds/${guildId}/voice/volume`, {});
|
||||
return response?.data?.volume || 0;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ interface GetSpellsParams {
|
||||
}
|
||||
|
||||
export async function getSpells(params?: GetSpellsParams): Promise<GetSpellsResponse> {
|
||||
const response = await getRequest('spells', {
|
||||
const response = await getRequest('dnd/spells', {
|
||||
name: params?.name,
|
||||
like_name: params?.like_name,
|
||||
schools: params?.schools?.join(','),
|
||||
|
||||
@@ -7,11 +7,13 @@ import {
|
||||
pauseTrack,
|
||||
playTrack,
|
||||
resumeTrack,
|
||||
sendMessage,
|
||||
setVolume,
|
||||
skipTrack,
|
||||
stopTrack
|
||||
} from '@/api/guilds';
|
||||
import { GuildChannel, GuildInfo } from '@/api/guilds.types';
|
||||
import { Button, Slider, Tabs, TextInput } from '@mantine/core';
|
||||
import { Button, Slider, Tabs, TextInput, Textarea } from '@mantine/core';
|
||||
import { useForm } from '@mantine/form';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
@@ -39,6 +41,7 @@ export default function Page() {
|
||||
|
||||
const playForm = useForm({
|
||||
initialValues: {
|
||||
message: '',
|
||||
trackUrl: '',
|
||||
volume: 50.0
|
||||
}
|
||||
@@ -48,26 +51,32 @@ export default function Page() {
|
||||
<Tabs orientation='vertical' defaultValue={activeGuild?.name}>
|
||||
<Tabs.List>
|
||||
{guilds.map((guild) => (
|
||||
<Tabs.Tab key={guild.id} value={guild.name} onClick={() => setActiveGuild(guild)}>
|
||||
<Tabs.Tab key={`guild-tab-${guild.id}`} value={guild.name} onClick={() => setActiveGuild(guild)}>
|
||||
{guild.name}
|
||||
</Tabs.Tab>
|
||||
))}
|
||||
</Tabs.List>
|
||||
{guilds.map((guild) => (
|
||||
<Tabs.Panel key={guild.id} value={guild.name}>
|
||||
<Tabs.Panel key={`guild-${guild.id}`} value={guild.name}>
|
||||
<h1>{guild.name}</h1>
|
||||
<h2>Text Channels</h2>
|
||||
<Tabs orientation='horizontal' defaultValue={textChannels[0]?.name}>
|
||||
<Tabs.List>
|
||||
{textChannels.map((channel) => (
|
||||
<Tabs.Tab key={channel.id} value={channel.name}>
|
||||
<Tabs.Tab key={`text-channel-tab-${channel.id}`} value={channel.name}>
|
||||
{channel.name}
|
||||
</Tabs.Tab>
|
||||
))}
|
||||
</Tabs.List>
|
||||
{textChannels.map((channel) => (
|
||||
<Tabs.Panel key={channel.id} value={channel.name}>
|
||||
{channel.name}
|
||||
<Tabs.Panel key={`text-channel-${channel.id}`} value={channel.name}>
|
||||
<form
|
||||
style={{ margin: '1em' }}
|
||||
onSubmit={playForm.onSubmit((values) => sendMessage(activeGuild!.id, channel.id, values.message))}
|
||||
>
|
||||
<Textarea placeholder='Message...' {...playForm.getInputProps('message')} />
|
||||
<Button type='submit'>Send Message</Button>
|
||||
</form>
|
||||
</Tabs.Panel>
|
||||
))}
|
||||
</Tabs>
|
||||
@@ -75,14 +84,13 @@ export default function Page() {
|
||||
<Tabs orientation='horizontal' defaultValue={voiceChannels[0]?.name}>
|
||||
<Tabs.List>
|
||||
{voiceChannels.map((channel) => (
|
||||
<Tabs.Tab key={channel.id} value={channel.name}>
|
||||
<Tabs.Tab key={`voice-channel-tab-${channel.id}`} value={channel.name}>
|
||||
{channel.name}
|
||||
</Tabs.Tab>
|
||||
))}
|
||||
</Tabs.List>
|
||||
{voiceChannels.map((channel) => (
|
||||
<Tabs.Panel key={channel.id} value={channel.name}>
|
||||
{channel.name}
|
||||
<Tabs.Panel key={`voice-channel-${channel.id}`} value={channel.name}>
|
||||
<form
|
||||
style={{ margin: '1em' }}
|
||||
onSubmit={playForm.onSubmit((values) => {
|
||||
@@ -91,6 +99,7 @@ export default function Page() {
|
||||
>
|
||||
<TextInput placeholder='Youtube URL...' {...playForm.getInputProps('trackUrl')} />
|
||||
<Button type='submit'>Play Track</Button>
|
||||
<Button onClick={() => skipTrack(activeGuild!.id)}>Skip Track</Button>
|
||||
</form>
|
||||
<div style={{ margin: '1em' }}>
|
||||
<Button style={{ marginRight: '1em' }} onClick={() => stopTrack(activeGuild!.id)}>
|
||||
@@ -105,23 +114,18 @@ export default function Page() {
|
||||
</div>
|
||||
<form
|
||||
style={{ margin: '1em' }}
|
||||
onSubmit={playForm.onSubmit((values) => {
|
||||
setVolume(activeGuild!.id, values.volume)
|
||||
})}
|
||||
onSubmit={playForm.onSubmit((values) => setVolume(activeGuild!.id, values.volume))}
|
||||
>
|
||||
<Slider
|
||||
defaultValue={50}
|
||||
{...playForm.getInputProps('volume')}
|
||||
marks={[
|
||||
|
||||
{ value: 25, label: '25%' },
|
||||
{ value: 50, label: '50%' },
|
||||
{ value: 75, label: '75%' },
|
||||
{ value: 75, label: '75%' }
|
||||
]}
|
||||
/>
|
||||
<Button type='submit'>
|
||||
Set Volume
|
||||
</Button>
|
||||
<Button type='submit'>Set Volume</Button>
|
||||
</form>
|
||||
</Tabs.Panel>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user