Skip to content

Commit

Permalink
Fix code because of dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
byte-sized-emi committed Mar 2, 2024
1 parent 5f3df00 commit 59b9cef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
11 changes: 5 additions & 6 deletions src/bot/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::time::SystemTime;
use poise::CreateReply;

use crate::bot::{Context, Error};

pub mod subject;
Expand All @@ -9,15 +11,12 @@ pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
let response = "Pong!";
let now = SystemTime::now();
let reply_message = ctx.say(response).await?;
reply_message
.edit(ctx, |builder| {
builder.content(match now.elapsed() {
reply_message.edit(ctx, CreateReply::default().content(
match now.elapsed() {
Ok(elapsed) => {
format!("Pong: {} ms", elapsed.as_millis())
}
Err(_) => "Pong: could not calculate time difference".to_owned(),
})
})
.await?;
})).await?;
Ok(())
}
29 changes: 13 additions & 16 deletions src/bot/commands/subject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use futures::future::join_all;
use itertools::Itertools;
use poise::serenity_prelude::{ChannelId, ChannelType, GuildId, RoleId};
use poise::serenity_prelude::{ChannelId, ChannelType, CreateChannel, EditRole, GuildId, RoleId};
use sqlx::{MySql, Pool};
use tracing::{trace, warn};

use crate::{
bot::{Context, Error},
Expand Down Expand Up @@ -63,13 +62,13 @@ pub async fn add(
let mut message = String::new();

if !present_roles.is_empty() {
let present_roles_fmt = present_roles.iter().map(|role| format!("<@&{}>", role.0)).join("\n");
let present_roles_fmt = present_roles.iter().map(|role| format!("<@&{}>", role.get())).join("\n");

message.push_str(format!("Ignoring subjects that you already have:\n{present_roles_fmt}\n").as_str());
}

if !missing_roles.is_empty() {
let missing_roles_fmt = missing_roles.iter().map(|role| format!("<@&{}>", role.0)).join("\n");
let missing_roles_fmt = missing_roles.iter().map(|role| format!("<@&{}>", role.get())).join("\n");

message.push_str(format!("Added following subjects to you:\n{missing_roles_fmt}").as_str());
}
Expand Down Expand Up @@ -121,13 +120,13 @@ pub async fn remove(
let mut message = String::new();

if !missing_roles.is_empty() {
let missing_roles_fmt = missing_roles.iter().map(|role| format!("<@&{}>", role.0)).join("\n");
let missing_roles_fmt = missing_roles.iter().map(|role| format!("<@&{}>", role.get())).join("\n");

message.push_str(format!("Ignoring subjects that you don't have:\n{missing_roles_fmt}").as_str());
}

if !present_roles.is_empty() {
let present_roles_fmt = present_roles.iter().map(|role| format!("<@&{}>", role.0)).join("\n");
let present_roles_fmt = present_roles.iter().map(|role| format!("<@&{}>", role.get())).join("\n");

message.push_str(format!("Removing subjects:\n{present_roles_fmt}\n").as_str());
}
Expand Down Expand Up @@ -288,11 +287,11 @@ pub async fn create(ctx: Context<'_>, name: String) -> Result<(), Error> {
}

let db_guild = mysql_lib::get_guild(db, guild_id).await.unwrap();
let discord_guild = ctx.guild().unwrap();
let discord_guild = ctx.partial_guild().await.unwrap();

// create role
let new_role = discord_guild
.create_role(discord_http, |r| r.name(&name).mentionable(true))
.create_role(discord_http, EditRole::default().name(&name).mentionable(true))
.await?;

let role = new_role.id;
Expand All @@ -301,12 +300,10 @@ pub async fn create(ctx: Context<'_>, name: String) -> Result<(), Error> {
let base_category = db_guild.subject_group_category;

let new_channel = discord_guild
.create_channel(discord_http, |c| {
c.category(base_category)
.name(&name)
.kind(ChannelType::Text)
})
.await?;
.create_channel(discord_http, CreateChannel::new(&name)
.category(base_category)
.kind(ChannelType::Text))
.await?;

let text_channel = new_channel.id;

Expand Down Expand Up @@ -345,7 +342,7 @@ pub async fn delete(ctx: Context<'_>, role: RoleId) -> Result<(), Error> {
}
};

let discord_guild = ctx.guild().unwrap();
let discord_guild = ctx.partial_guild().await.unwrap();
let discord_http = ctx.http();

discord_guild.delete_role(discord_http, role).await?;
Expand All @@ -358,7 +355,7 @@ pub async fn delete(ctx: Context<'_>, role: RoleId) -> Result<(), Error> {
role,
guild_id,
name: "".to_string(),
text_channel: ChannelId(0),
text_channel: ChannelId::new(u64::MAX),
};

match mysql_lib::delete_subject(db, subject).await {
Expand Down
6 changes: 3 additions & 3 deletions src/mysql_lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,8 @@ pub async fn get_subjects(pool: &Pool<MySql>, guild_id: GuildId) -> Option<Vec<D

pub async fn get_subject_for_role(pool: &Pool<MySql>, guild_id: GuildId, role: RoleId) -> Option<DatabaseSubject> {
match sqlx::query_as::<_, DatabaseSubject>("SELECT * FROM Subject WHERE guild_id=? AND role=?")
.bind(guild_id.0)
.bind(role.0)
.bind(guild_id.get())
.bind(role.get())
.fetch_one(pool)
.await
{
Expand Down Expand Up @@ -1231,7 +1231,7 @@ pub async fn get_subjects_for_semester_study_group(
ON Subject.role = Study_subject_link.subject_role
WHERE study_group_role=?"
)
.bind(semester_study_group_role.0)
.bind(semester_study_group_role.get())
.fetch_all(pool)
.await
{
Expand Down

0 comments on commit 59b9cef

Please sign in to comment.