test1
This commit is contained in:
parent
05814dd0e7
commit
9d5b56344e
12 changed files with 3012 additions and 108 deletions
|
@ -5,9 +5,9 @@ use crate::commands::lfg::Mode::*;
|
|||
//from main.rs
|
||||
use crate::{Context, Error};
|
||||
//
|
||||
use serenity::model::id::{RoleId};
|
||||
use serenity::model::id::RoleId;
|
||||
use serenity::model::mention::Mention;
|
||||
use serenity::model::mention::Mention::{Role};
|
||||
use serenity::model::mention::Mention::Role;
|
||||
|
||||
#[derive(Debug, poise::ChoiceParameter, PartialEq)]
|
||||
pub enum Map {
|
||||
|
@ -40,8 +40,7 @@ pub enum Difficulty {
|
|||
pub(crate) async fn lfg(
|
||||
ctx: Context<'_>,
|
||||
|
||||
#[rename = "map"]
|
||||
map: Map,
|
||||
#[rename = "map"] map: Map,
|
||||
|
||||
#[description = "Normal"]
|
||||
#[rename = "difficulty"]
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
use std::convert::Into;
|
||||
use crate::{Context, Error};
|
||||
use crate::commands::zombies::zombies::*;
|
||||
use crate::{Context, Error};
|
||||
use std::convert::Into;
|
||||
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn round(
|
||||
ctx: Context<'_>
|
||||
) -> Result<(), Error> {
|
||||
pub(crate) async fn round(ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
|
@ -5,10 +5,10 @@ use crate::commands::zombies::gear::WeaponMaterial::{Diamond, Gold, Wood};
|
|||
#[derive(Debug)]
|
||||
pub enum ArmorPiece {
|
||||
None,
|
||||
Helmet(ArmorMaterial),
|
||||
Chestplate(ArmorMaterial),
|
||||
Leggings(ArmorMaterial),
|
||||
Boots(ArmorMaterial)
|
||||
Helmet(HelmetType),
|
||||
Chestplate(ArmorMaterial, Enchanted),
|
||||
Leggings(ArmorMaterial, Enchanted),
|
||||
Boots(ArmorMaterial, Enchanted),
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum WeaponMaterial {
|
||||
|
@ -16,31 +16,38 @@ pub enum WeaponMaterial {
|
|||
Stone,
|
||||
Gold,
|
||||
Iron,
|
||||
Diamond
|
||||
Diamond,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum HelmetType {
|
||||
Head(u32),
|
||||
Helmet(ArmorMaterial, Enchanted),
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum ArmorMaterial {
|
||||
Leather,
|
||||
Leather(u32),
|
||||
Gold,
|
||||
Chainmail,
|
||||
Iron,
|
||||
Diamond
|
||||
Diamond,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum Weapon {
|
||||
None,
|
||||
Axe(WeaponMaterial),
|
||||
Sword(WeaponMaterial)
|
||||
Axe(WeaponMaterial, Enchanted),
|
||||
Sword(WeaponMaterial, Enchanted),
|
||||
|
||||
SlimeBall(Enchanted),
|
||||
}
|
||||
pub type Enchanted = bool;
|
||||
pub const NO_WEAPON: Weapon = Weapon::None;
|
||||
pub const WOODEN_AXE:Weapon = Axe(Wood);
|
||||
pub const DIAMOND_AXE:Weapon = Axe(Diamond);
|
||||
pub const GOLD_SWORD:Weapon = Sword(Gold);
|
||||
pub const DIAMOND_SWORD:Weapon = Sword(Diamond);
|
||||
pub const WOODEN_AXE: Weapon = Axe(Wood, false);
|
||||
pub const DIAMOND_AXE: Weapon = Axe(Diamond, false);
|
||||
pub const GOLD_SWORD: Weapon = Sword(Gold, false);
|
||||
pub const DIAMOND_SWORD: Weapon = Sword(Diamond, false);
|
||||
pub const SLIME_BALL: Weapon = Weapon::SlimeBall(true);
|
||||
|
||||
pub const NO_HELMET: ArmorPiece = ArmorPiece::None;
|
||||
pub const NO_CHESTPLATE: ArmorPiece = ArmorPiece::None;
|
||||
pub const NO_LEGGINGS: ArmorPiece = ArmorPiece::None;
|
||||
pub const NO_BOOTS: ArmorPiece = ArmorPiece::None;
|
||||
|
||||
pub const LEATHER_LEGGINGS:ArmorPiece = Leggings(Leather);
|
|
@ -1,3 +1,3 @@
|
|||
pub mod zombies;
|
||||
pub mod gear;
|
||||
pub(crate) mod rounds;
|
||||
pub mod zombies;
|
||||
|
|
|
@ -1,53 +1,43 @@
|
|||
use crate::commands::zombies::rounds::Round::*;
|
||||
use crate::commands::zombies::rounds::Wave::*;
|
||||
use crate::commands::zombies::zombies::*;
|
||||
/*type Wave = Vec<Horde>;
|
||||
type Round = Vec<Wave>;
|
||||
|
||||
fn bad_blood_round1() -> Round {
|
||||
let mut round:Round = Vec::with_capacity(2);
|
||||
let mut wave1:Wave = Vec::with_capacity(2);
|
||||
let mut wave2:Wave = Vec::with_capacity(1);
|
||||
wave1.push(Horde {
|
||||
zombie: BB_Z_1,
|
||||
count: 4
|
||||
});
|
||||
wave2.push(Horde {
|
||||
zombie: BB_Z_1,
|
||||
count: 5
|
||||
});
|
||||
round.push(wave1);
|
||||
round.push(wave2);
|
||||
round
|
||||
}*/
|
||||
struct Wave {
|
||||
hordes: Vec<Horde>,
|
||||
}
|
||||
struct Round {
|
||||
waves: Vec<Wave>,
|
||||
}
|
||||
|
||||
pub enum Wave {
|
||||
Wave1horde([Horde;1]),
|
||||
Wave2hordes([Horde;2]),
|
||||
Wave3hordes([Horde;3]),
|
||||
Wave4hordes([Horde;4]),
|
||||
Wave5hordes([Horde;5]),
|
||||
Wave6hordes([Horde;6]),
|
||||
Wave7hordes([Horde;7])
|
||||
fn get_bb_r1() -> Vec<Wave> {
|
||||
vec![
|
||||
Wave {
|
||||
hordes: vec![
|
||||
Horde {
|
||||
zombie: BB_Z_1,
|
||||
count: 4,
|
||||
}
|
||||
]
|
||||
},
|
||||
Wave {
|
||||
hordes: vec![
|
||||
Horde {
|
||||
zombie: BB_Z_1,
|
||||
count: 5,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
pub(crate) fn get_bb_by_round(round: u8) {
|
||||
match round {
|
||||
1 => t(get_bb_r1()),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
fn t(waves:Vec<Wave>) {
|
||||
for wave in waves {
|
||||
let hordes:Vec<Horde> = wave.hordes;
|
||||
for horde in hordes {
|
||||
println!("{:?} x {}", horde.zombie, horde.count);
|
||||
}
|
||||
}
|
||||
pub enum Round {
|
||||
Round2Waves([Wave;2]),
|
||||
Round3Waves([Wave;3]),
|
||||
Round4Waves([Wave;4]),
|
||||
Round5Waves([Wave;5]),
|
||||
Round6Waves([Wave;6]),
|
||||
Round7Waves([Wave;7])
|
||||
}
|
||||
const DE:[Round;30] = [
|
||||
Round2Waves([
|
||||
Wave1horde([
|
||||
Horde { zombie: BB_Z_1, count: 4 }
|
||||
]),
|
||||
Wave1horde([
|
||||
Horde { zombie: BB_Z_1, count: 5 }
|
||||
])
|
||||
]);30
|
||||
];
|
||||
/*fn t() {
|
||||
DE.get(2)
|
||||
}*/
|
|
@ -1,19 +1,23 @@
|
|||
use crate::commands::zombies::gear::ArmorMaterial::Leather;
|
||||
use crate::commands::zombies::gear::HelmetType::Head;
|
||||
use crate::commands::zombies::gear::*;
|
||||
use crate::{Context, Error};
|
||||
use ArmorPiece::Leggings;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Zombie {
|
||||
id: u16,
|
||||
damage: u8,
|
||||
health: u16,
|
||||
speed: f32,
|
||||
armor: [ArmorPiece;4],
|
||||
weapon: Weapon,
|
||||
follow_range: u8
|
||||
pub(crate) id: u16,
|
||||
pub(crate) damage: u8,
|
||||
pub(crate) health: u16,
|
||||
pub(crate) speed: f32,
|
||||
pub(crate) armor: [ArmorPiece; 4],
|
||||
pub(crate) weapon: Weapon,
|
||||
pub(crate) follow_range: u8,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct Horde {
|
||||
pub zombie: Zombie,
|
||||
pub count: u8
|
||||
pub(crate) zombie: Zombie,
|
||||
pub(crate) count: u8,
|
||||
}
|
||||
|
||||
pub const BB_Z_1: Zombie = Zombie {
|
||||
|
@ -21,7 +25,21 @@ pub const BB_Z_1: Zombie = Zombie {
|
|||
damage: 3,
|
||||
health: 20,
|
||||
speed: 0.25,
|
||||
armor: [NO_HELMET,NO_CHESTPLATE,LEATHER_LEGGINGS,NO_BOOTS],
|
||||
armor: [NO_HELMET, NO_CHESTPLATE, NO_LEGGINGS, NO_BOOTS],
|
||||
weapon: WOODEN_AXE,
|
||||
follow_range: 35
|
||||
follow_range: 35,
|
||||
};
|
||||
pub const BB_S_1: Zombie = Zombie {
|
||||
id: 2,
|
||||
damage: 4,
|
||||
health: 25,
|
||||
speed: 0.25,
|
||||
armor: [
|
||||
ArmorPiece::Helmet(Head(3)),
|
||||
ArmorPiece::Chestplate(Leather(3), false),
|
||||
Leggings(Leather(3), false),
|
||||
ArmorPiece::Boots(Leather(3), false),
|
||||
],
|
||||
weapon: SLIME_BALL,
|
||||
follow_range: 35,
|
||||
};
|
24
src/main.rs
24
src/main.rs
|
@ -1,11 +1,11 @@
|
|||
mod commands;
|
||||
|
||||
use poise::{async_trait, Event, serenity_prelude as serenity};
|
||||
use crate::commands::round::round;
|
||||
use poise::{async_trait, serenity_prelude as serenity, Event};
|
||||
use serenity::client::EventHandler;
|
||||
use serenity::model::id::UserId;
|
||||
use std::collections::HashSet;
|
||||
use std::convert::Into;
|
||||
use serenity::client::EventHandler;
|
||||
use crate::commands::round::round;
|
||||
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
@ -14,12 +14,15 @@ struct ReadyHandler;
|
|||
|
||||
#[async_trait]
|
||||
impl EventHandler for ReadyHandler {
|
||||
async fn ready(&self, _: poise::serenity_prelude::Context, ready: poise::serenity_prelude::Ready) {
|
||||
async fn ready(
|
||||
&self,
|
||||
_: poise::serenity_prelude::Context,
|
||||
ready: poise::serenity_prelude::Ready,
|
||||
) {
|
||||
println!("{} is connected!", ready.user.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let options = poise::FrameworkOptions {
|
||||
|
@ -44,28 +47,19 @@ async fn main() {
|
|||
}
|
||||
})
|
||||
},
|
||||
owners: {
|
||||
HashSet::from([UserId(449579075531440128_u64)])
|
||||
},
|
||||
owners: { HashSet::from([UserId(449579075531440128_u64)]) },
|
||||
event_handler: |_ctx, event, _framework, _data| {
|
||||
Box::pin(event_handler(_ctx, event, _framework, _data))
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
|
||||
.options(options)
|
||||
|
||||
.token(std::env::var("DISCORD_TOKEN").unwrap())
|
||||
|
||||
.intents(
|
||||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT,
|
||||
)
|
||||
|
||||
.setup(move |ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
|
|
3
y/.gitignore
vendored
Normal file
3
y/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/target
|
||||
.shuttle-storage
|
||||
Secrets*.toml
|
2823
y/Cargo.lock
generated
Normal file
2823
y/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
14
y/Cargo.toml
Normal file
14
y/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "zmp-bot"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.68"
|
||||
poise = "0.5.2"
|
||||
shuttle-poise = "0.30.0"
|
||||
shuttle-runtime = "0.30.0"
|
||||
shuttle-secrets = "0.30.0"
|
||||
tracing = "0.1.37"
|
||||
tokio = "1.26.0"
|
16
y/README.md
Normal file
16
y/README.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Poise Hello World Bot with Shuttle
|
||||
|
||||
In this example we will deploy a Poise/Serenity bot with Shuttle that responds to the `/hello` command with `world!`. To run this bot we need a valid Discord Token. To get started log in to the [Discord developer portal](https://discord.com/developers/applications).
|
||||
|
||||
1. Click the New Application button, name your application and click Create.
|
||||
2. Navigate to the Bot tab in the lefthand menu, and add a new bot.
|
||||
3. On the bot page click the Reset Token button to reveal your token. Put this token in your `Secrets.toml`. It's very important that you don't reveal your token to anyone, as it can be abused. Create a `.gitignore` file to omit your `Secrets.toml` from version control.
|
||||
4. For the sake of this example, you also need to scroll down on the bot page to the Message Content Intent section and enable that option.
|
||||
|
||||
To add the bot to a server we need to create an invite link.
|
||||
|
||||
1. On your bot's application page, open the OAuth2 page via the lefthand panel.
|
||||
2. Go to the URL Generator via the lefthand panel, and select the `bot` scope as well as the `Send Messages` permission in the Bot Permissions section.
|
||||
3. Copy the URL, open it in your browser and select a Discord server you wish to invite the bot to.
|
||||
|
||||
For more information please refer to the [Discord docs](https://discord.com/developers/docs/getting-started) as well as the [Poise docs](https://docs.rs/poise) for more examples.
|
42
y/src/main.rs
Normal file
42
y/src/main.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use anyhow::Context as _;
|
||||
use poise::serenity_prelude as serenity;
|
||||
use shuttle_poise::ShuttlePoise;
|
||||
use shuttle_secrets::SecretStore;
|
||||
|
||||
struct Data {} // User data, which is stored and accessible in all command invocations
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
/// Responds with "world!"
|
||||
#[poise::command(slash_command)]
|
||||
async fn hello(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say("world!").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[shuttle_runtime::main]
|
||||
async fn poise(#[shuttle_secrets::Secrets] secret_store: SecretStore) -> ShuttlePoise<Data, Error> {
|
||||
// Get the discord token set in `Secrets.toml`
|
||||
let discord_token = secret_store
|
||||
.get("DISCORD_TOKEN")
|
||||
.context("'DISCORD_TOKEN' was not found")?;
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![hello()],
|
||||
..Default::default()
|
||||
})
|
||||
.token(discord_token)
|
||||
.intents(serenity::GatewayIntents::non_privileged())
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {})
|
||||
})
|
||||
})
|
||||
.build()
|
||||
.await
|
||||
.map_err(shuttle_runtime::CustomError::new)?;
|
||||
|
||||
Ok(framework.into())
|
||||
}
|
Loading…
Add table
Reference in a new issue