Compare commits

...

2 commits

Author SHA1 Message Date
LordMZTE 8df1e025c2 add drone cicd
All checks were successful
continuous-integration/drone/push Build is passing
2021-01-15 19:17:54 +01:00
LordMZTE 4d592bd3d1 memes in config may now be lowercase 2021-01-15 19:08:38 +01:00
6 changed files with 92 additions and 4 deletions

46
.drone.yml Normal file
View 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
View file

@ -0,0 +1,5 @@
v0.1.0
# ruff
initial release
- does everything to old uffbot could

View file

@ -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

View file

@ -50,3 +50,4 @@ impl<'de> Deserialize<'de> for Event {
deserializer.deserialize_str(EventVisitor)
}
}

View file

@ -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))
}
}

View file

@ -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,