Compare commits
2 commits
75339638c6
...
8df1e025c2
Author | SHA1 | Date | |
---|---|---|---|
LordMZTE | 8df1e025c2 | ||
LordMZTE | 4d592bd3d1 |
46
.drone.yml
Normal file
46
.drone.yml
Normal file
|
@ -0,0 +1,46 @@
|
|||
kind: pipeline
|
||||
name: tests
|
||||
steps:
|
||||
- name: test-linux
|
||||
image: rust
|
||||
commands:
|
||||
- cargo test -v
|
||||
|
||||
# Try to build docker image
|
||||
- name: test-docker-build
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: lordmzte/ruff
|
||||
# Don't push
|
||||
dry_run: true
|
||||
---
|
||||
kind: pipeline
|
||||
name: release
|
||||
steps:
|
||||
- name: release-linux
|
||||
image: rust
|
||||
commands:
|
||||
- cargo build --release -v
|
||||
|
||||
- name: release-win
|
||||
image: lordmzte/rust-win
|
||||
commands:
|
||||
- cargo build --release --target x86_64-pc-windows-gnu -v
|
||||
|
||||
- name: publish
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
base_url: https://data.tilera.xyz/git
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
note: CHANGELOG.md
|
||||
title: tag-${DRONE_TAG}
|
||||
files:
|
||||
- target/release/ruff
|
||||
- target/x86_64-pc-windows-gnu/release/ruff.exe
|
||||
when:
|
||||
event: tag
|
||||
depends_on:
|
||||
- release-linux
|
||||
- release-win
|
||||
|
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
v0.1.0
|
||||
# ruff
|
||||
initial release
|
||||
- does everything to old uffbot could
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
# RUFF
|
||||
|
||||
[![Build Status](https://drone.tilera.xyz/api/badges/LordMZTE/RUFF/status.svg)](https://drone.tilera.xyz/LordMZTE/RUFF)
|
||||
|
||||
The successor to ITbyHF's crappy golang UFFbot written in rust and compatible with most chat platforms through matterbridge.
|
||||
|
||||
## Compiling
|
||||
|
|
|
@ -50,3 +50,4 @@ impl<'de> Deserialize<'de> for Event {
|
|||
deserializer.deserialize_str(EventVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
use anyhow::{Context, Result};
|
||||
use once_cell::sync::OnceCell;
|
||||
use serde::Deserialize;
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use serde::{Deserialize, de::{Deserializer, MapAccess, Visitor}};
|
||||
use std::{collections::HashMap, path::PathBuf, marker::PhantomData};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
pub nickname: String,
|
||||
pub gateways: Vec<String>,
|
||||
pub api: String,
|
||||
pub memes: HashMap<String, String>,
|
||||
pub memes: LowerCaseMap<String>,
|
||||
}
|
||||
|
||||
static CONFIG: OnceCell<Config> = OnceCell::new();
|
||||
|
@ -35,3 +36,36 @@ pub async fn try_get_config<'a>() -> Result<&'a Config> {
|
|||
Some(c) => Ok(c),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LowerCaseMap<T> {
|
||||
pub map: HashMap<String, T>
|
||||
}
|
||||
|
||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for LowerCaseMap<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<LowerCaseMap<T>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct LowerCaseMapVisitor<T>(PhantomData<T>);
|
||||
|
||||
impl<'de, T: Deserialize<'de>> Visitor<'de> for LowerCaseMapVisitor<T> {
|
||||
type Value = LowerCaseMap<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a key-value pair with a string key")
|
||||
}
|
||||
|
||||
fn visit_map<A: MapAccess<'de>>(self, mut access: A) -> Result<Self::Value, A::Error> {
|
||||
let mut map = HashMap::new();
|
||||
while let Some((k, v)) = access.next_entry::<String, T>()? {
|
||||
map.insert(k.to_lowercase(), v);
|
||||
}
|
||||
|
||||
Ok(LowerCaseMap { map })
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_map(LowerCaseMapVisitor(PhantomData))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ async fn process_message(client: &Client, message: Message) -> Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(meme) = config.memes.get(&lower) {
|
||||
if let Some(meme) = config.memes.map.get(&lower) {
|
||||
log::info!(
|
||||
r#"found meme matching message "{}". responding with "{}""#,
|
||||
text,
|
||||
|
|
Loading…
Reference in a new issue