Add Twitter support.

This commit is contained in:
Syfaro 2019-11-08 02:04:38 -06:00
parent 430a86f2c9
commit a26918b32b
7 changed files with 700 additions and 76 deletions

View File

@ -4,20 +4,6 @@ name: default
type: docker
steps:
- name: restore
image: plugins/s3-cache
settings:
pull: true
restore: true
debug: true
root: cache
endpoint:
from_secret: s3_cache_endpoint
access_key:
from_secret: s3_cache_access_key
secret_key:
from_secret: s3_cache_secret_key
- name: docker
image: plugins/docker
settings:
@ -28,38 +14,4 @@ steps:
from_secret: docker_username
password:
from_secret: docker_password
- name: rebuild
image: plugins/s3-cache
settings:
pull: true
rebuild: true
debug: true
root: cache
endpoint:
from_secret: s3_cache_endpoint
access_key:
from_secret: s3_cache_access_key
secret_key:
from_secret: s3_cache_secret_key
mount:
- target
when:
event: push
- name: flush
image: plugins/s3-cache
settings:
pull: true
flush: true
flush_age: 14
debug: true
root: cache
endpoint:
from_secret: s3_cache_endpoint
access_key:
from_secret: s3_cache_access_key
secret_key:
from_secret: s3_cache_secret_key
...

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
target/
**/*.rs.bk
.env
*.db

269
Cargo.lock generated
View File

@ -63,11 +63,45 @@ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bincode"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.3.2"
@ -109,6 +143,7 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -207,6 +242,15 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crypto-mac"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cssparser"
version = "0.25.9"
@ -237,6 +281,14 @@ dependencies = [
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.4"
@ -250,6 +302,30 @@ dependencies = [
"dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "egg-mode"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ego-tree"
version = "0.6.2"
@ -309,6 +385,11 @@ dependencies = [
"synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fautil"
version = "0.1.0"
@ -351,9 +432,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "foxbot"
version = "0.1.0"
dependencies = [
"egg-mode 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fautil 0.1.0",
"linkify 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"pickledb 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -362,6 +445,7 @@ dependencies = [
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"telegram 0.1.0",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -414,6 +498,14 @@ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "generic-array"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "getopts"
version = "0.2.21"
@ -449,6 +541,11 @@ dependencies = [
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "half"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hermit-abi"
version = "0.1.3"
@ -457,6 +554,15 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hmac"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "html5ever"
version = "0.24.1"
@ -605,6 +711,11 @@ name = "libc"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "linked-hash-map"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "linkify"
version = "0.4.0"
@ -707,6 +818,16 @@ dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mio-uds"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "miow"
version = "0.2.1"
@ -781,6 +902,11 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "openssl"
version = "0.10.25"
@ -879,6 +1005,18 @@ dependencies = [
"siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pickledb"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pkg-config"
version = "0.3.17"
@ -1250,6 +1388,16 @@ dependencies = [
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_cbor"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"half 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "1.0.102"
@ -1281,6 +1429,17 @@ dependencies = [
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_yaml"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "servo_arc"
version = "0.1.1"
@ -1290,6 +1449,17 @@ dependencies = [
"stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sha-1"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "siphasher"
version = "0.2.3"
@ -1349,6 +1519,11 @@ name = "string_cache_shared"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "subtle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "1.0.7"
@ -1443,13 +1618,18 @@ dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1462,6 +1642,16 @@ dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-codec"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-current-thread"
version = "0.1.6"
@ -1480,6 +1670,16 @@ dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-fs"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-io"
version = "0.1.12"
@ -1557,6 +1757,37 @@ dependencies = [
"tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-udp"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-uds"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "try-lock"
version = "0.2.2"
@ -1570,6 +1801,11 @@ dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "typenum"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicase"
version = "2.5.1"
@ -1725,6 +1961,14 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "yaml-rust"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
@ -1734,7 +1978,11 @@ dependencies = [
"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea"
"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
"checksum bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8ab639324e3ee8774d296864fbc0dbbb256cf1a41c490b94cba90c082915f92"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
"checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
@ -1751,10 +1999,13 @@ dependencies = [
"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
"checksum cssparser 0.25.9 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe18ca4efb9ba3716c6da66cc3d7e673bf59fa576353011f48c4cfddbdd740e"
"checksum cssparser-macros 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5bb1c84e87c717666564ec056105052331431803d606bd45529b28547b611eef"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum dtoa-short 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "59020b8513b76630c49d918c33db9f4c91638e7d3404a28084083b87e33f76f2"
"checksum egg-mode 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e22c203f0b006bfd33496b5005fc3d5652f5c4967f7f4c1fea4fca8f59bcefd"
"checksum ego-tree 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a68a4904193147e0a8dec3314640e6db742afd5f6e634f428a6af230d9b3591"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
"checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9"
@ -1762,6 +2013,7 @@ dependencies = [
"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9"
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
"checksum flate2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
@ -1773,10 +2025,13 @@ dependencies = [
"checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
"checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407"
"checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462"
"checksum half 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ff54597ea139063f4225f1ec47011b03c9de4a486957ff3fc506881dac951d0"
"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120"
"checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695"
"checksum html5ever 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)" = "025483b0a1e4577bb28578318c886ee5f817dda6eb62473269349044406644cb"
"checksum http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf"
"checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d"
@ -1792,6 +2047,7 @@ dependencies = [
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum linkify 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03951527dd24d2c59f407502e7d88e0948ef06fac23335b556a4c2bc03c22096"
"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
@ -1804,6 +2060,7 @@ dependencies = [
"checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599"
"checksum miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625"
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e"
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
@ -1812,6 +2069,7 @@ dependencies = [
"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
"checksum num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "155394f924cdddf08149da25bfb932d226b4a593ca7468b08191ff6335941af5"
"checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
"checksum openssl 0.10.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2f372b2b53ce10fb823a337aaa674e3a7d072b957c6264d0f4ff0bd86e657449"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c977d08e1312e2f7e4b86f9ebaa0ed3b19d1daff75fae88bbb88108afbd801fc"
@ -1823,6 +2081,7 @@ dependencies = [
"checksum phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e"
"checksum phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662"
"checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0"
"checksum pickledb 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f84c239b2c2dc17025deda2d513de8218f1afd9ec7c34de45797ab35cf97d8a0"
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
@ -1864,10 +2123,13 @@ dependencies = [
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0"
"checksum serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45cd6d95391b16cd57e88b68be41d504183b7faae22030c0cc3b3f73dd57b2fd"
"checksum serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "ca13fc1a832f793322228923fbb3aba9f3f44444898f835d31ad1b74fa0a2bf8"
"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
"checksum servo_arc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d98238b800e0d1576d8b6e3de32827c2d74bee68bb97748dcf5071fb53965432"
"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68"
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "533e29e15d0748f28afbaf4ff7cab44d73e483a8e50b38c40bd13b7f3d48f542"
@ -1876,6 +2138,7 @@ dependencies = [
"checksum string_cache 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "89c058a82f9fd69b1becf8c274f412281038877c553182f1d02eb027045a2d67"
"checksum string_cache_codegen 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f45ed1b65bf9a4bf2f7b7dc59212d1926e9eaf00fa998988e420fd124467c6"
"checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
"checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
"checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c"
"checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
@ -1886,16 +2149,21 @@ dependencies = [
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6"
"checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46"
"checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f"
"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443"
"checksum tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f27ee0e6db01c5f0b2973824547ce7e637b2ed79b891a9677b0de9bd532b6ac"
"checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af"
"checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926"
"checksum tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c56391be9805bc80163151c0b9e5164ee64f4b0200962c346fea12773158f22d"
"checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76"
"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119"
"checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c"
"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e"
"checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b"
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b"
"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
"checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426"
@ -1918,3 +2186,4 @@ dependencies = [
"checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"
"checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d"

View File

@ -17,5 +17,9 @@ pretty_env_logger = "0.3.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
egg-mode = "0.13.0"
tokio = "0.1.21"
pickledb = "0.4.0"
telegram = { path = "./telegram" }
fautil = { path = "./fautil" }

View File

@ -2,6 +2,7 @@
use sites::{PostInfo, Site};
use telegram::*;
use tokio::runtime::current_thread::block_on_all;
mod sites;
@ -15,6 +16,8 @@ fn generate_id() -> String {
}
fn main() {
use pickledb::{PickleDb, PickleDbDumpPolicy, SerializationMethod};
pretty_env_logger::init();
let (fa_a, fa_b) = (
@ -22,15 +25,38 @@ fn main() {
std::env::var("FA_B").expect("Missing FA token b"),
);
let (consumer_key, consumer_secret) = (
std::env::var("TWITTER_CONSUMER_KEY").expect("Missing Twitter consumer key"),
std::env::var("TWITTER_CONSUMER_SECRET").expect("Missing Twitter consumer secret"),
);
let db_path = std::env::var("TWITTER_DATABASE").expect("Missing Twitter database path");
let mut db = PickleDb::load(
db_path.clone(),
PickleDbDumpPolicy::AutoDump,
SerializationMethod::Json,
)
.unwrap_or_else(|_| {
PickleDb::new(
db_path,
PickleDbDumpPolicy::AutoDump,
SerializationMethod::Json,
)
});
let fa_util_api = std::env::var("FAUTIL_APITOKEN").expect("Missing FA Utility API token");
let fapi = fautil::FAUtil::new(fa_util_api.clone());
let mut sites: Vec<Box<dyn Site>> = vec![
Box::new(sites::e621::new()),
Box::new(sites::E621::new()),
Box::new(sites::FurAffinity::new((fa_a, fa_b), fa_util_api)),
Box::new(sites::Weasyl::new(
std::env::var("WEASYL_APITOKEN").expect("Missing Weasyl API token"),
)),
Box::new(sites::Twitter::new(
consumer_key.clone(),
consumer_secret.clone(),
)),
Box::new(sites::Mastodon::new()),
Box::new(sites::Direct::new()),
];
@ -69,7 +95,7 @@ fn main() {
if site.is_supported(link_str) {
log::debug!("Link {} supported by {}", link_str, site.name());
let images = match site.get_images(link_str) {
let images = match site.get_images(inline.from.id, link_str) {
Ok(images) => images,
Err(_) => continue 'link,
};
@ -91,8 +117,7 @@ fn main() {
let mut responses: Vec<InlineQueryResult> = results
.iter()
.map(process_result)
.filter(Option::is_some)
.map(std::option::Option::unwrap)
.filter_map(|result| result)
.flatten()
.collect();
@ -116,6 +141,112 @@ fn main() {
} else if let Some(message) = update.message {
if message.photo.is_some() {
process_photo(&bot, &fapi, message);
} else if let Some(entities) = message.entities {
let command = entities
.iter()
.find(|entity| entity.entity_type == MessageEntityType::BotCommand);
let command = match command {
Some(command) => command,
None => continue,
};
let text = message.text.unwrap();
let command_text: String = text
.chars()
.skip(command.offset as usize)
.take(command.length as usize)
.collect();
let args: String = text
.chars()
.skip((command.offset + command.length + 1) as usize)
.collect();
log::debug!("Got command: {}", command_text);
log::trace!("Command {} had arguments: {}", command_text, args);
match command_text.as_ref() {
"/twitter" => {
authenticate_twitter(
&mut db,
&bot,
message.message_id,
&message.from.unwrap(),
);
}
_ => log::info!("Unknown command: {}", command_text),
};
} else if let Some(text) = message.text {
let from = message.from.unwrap();
log::trace!("Checking if message was Twitter code");
let data: (String, String) = match db.get(&format!("authenticate:{}", from.id))
{
Some(data) => data,
None => continue,
};
log::trace!("We had waiting Twitter code");
let request_token = egg_mode::KeyPair::new(data.0, data.1);
let con_token =
egg_mode::KeyPair::new(consumer_key.clone(), consumer_secret.clone());
let token =
match block_on_all(egg_mode::access_token(con_token, &request_token, text))
{
Err(e) => {
log::warn!("User was unable to verify OOB: {:?}", e);
let message = SendMessage {
chat_id: from.id.into(),
text: "Something went wrong, please try again later."
.to_string(),
reply_markup: None,
reply_to_message_id: Some(message.message_id),
};
let _ = bot.make_request(&message);
return;
}
Ok(token) => token,
};
log::trace!("Got token");
let access = match token.0 {
egg_mode::Token::Access {
access,
..
} => access,
_ => unimplemented!(),
};
log::trace!("Got access token");
if let Err(e) = db.set(
&format!("credentials:{}", from.id),
&(access.key, access.secret),
) {
log::warn!("Unable to save user credentials: {:?}", e);
let message = SendMessage {
chat_id: from.id.into(),
text: "Something went wrong, please try again later.".to_string(),
reply_markup: None,
reply_to_message_id: Some(message.message_id),
};
let _ = bot.make_request(&message);
return;
}
let message = SendMessage {
chat_id: from.id.into(),
text: format!("Welcome aboard, {}!", token.2),
reply_markup: None,
reply_to_message_id: Some(message.message_id),
};
let _ = bot.make_request(&message);
}
}
@ -124,6 +255,66 @@ fn main() {
}
}
fn authenticate_twitter(db: &mut pickledb::PickleDb, bot: &Telegram, id: i32, user: &User) {
let (consumer_key, consumer_secret) = (
std::env::var("TWITTER_CONSUMER_KEY").expect("Missing Twitter consumer key"),
std::env::var("TWITTER_CONSUMER_SECRET").expect("Missing Twitter consumer secret"),
);
let con_token = egg_mode::KeyPair::new(consumer_key, consumer_secret);
let request_token = match block_on_all(egg_mode::request_token(&con_token, "oob")) {
Ok(req) => req,
Err(e) => {
log::warn!("Unable to get request token: {:?}", e);
let message = SendMessage {
chat_id: user.id.into(),
text: "Something went wrong, please try again later.".to_string(),
reply_markup: None,
reply_to_message_id: Some(id),
};
let _ = bot.make_request(&message);
return;
}
};
if let Err(e) = db.set(
&format!("authenticate:{}", user.id),
&(request_token.key.clone(), request_token.secret.clone()),
) {
log::warn!("Unable to save authenticate: {:?}", e);
let message = SendMessage {
chat_id: user.id.into(),
text: "Something went wrong, please try again later.".to_string(),
reply_markup: None,
reply_to_message_id: Some(id),
};
let _ = bot.make_request(&message);
return;
}
let url = egg_mode::authorize_url(&request_token);
let message = SendMessage {
chat_id: user.id.into(),
text: format!(
"Please follow the link and enter the 6 digit code returned: {}",
url
),
reply_markup: Some(ReplyMarkup::ForceReply(ForceReply {
force_reply: true,
selective: true,
})),
reply_to_message_id: Some(id),
};
let _ = bot.make_request(&message);
}
fn get_empty_query() -> InlineQueryResult {
InlineQueryResult::article(
generate_id(),
@ -220,7 +411,20 @@ fn process_photo(bot: &Telegram, fapi: &fautil::FAUtil, message: Message) {
let matches = match fapi.image_search(photo) {
Ok(matches) if !matches.is_empty() => matches,
_ => return,
_ => {
let message = SendMessage {
chat_id: message.chat.id.into(),
text: "I was unable to find anything, sorry.".to_owned(),
reply_to_message_id: Some(message.message_id),
reply_markup: None,
};
if let Err(e) = bot.make_request(&message) {
log::error!("Unable to respond to photo: {:?}", e);
}
return;
}
};
let first = matches.get(0).unwrap();
@ -231,6 +435,8 @@ fn process_photo(bot: &Telegram, fapi: &fautil::FAUtil, message: Message) {
"I found this: https://www.furaffinity.net/view/{}/",
first.id
),
reply_to_message_id: Some(message.message_id),
reply_markup: None,
};
if let Err(e) = bot.make_request(&message) {

View File

@ -1,5 +1,6 @@
use serde::Deserialize;
use std::collections::HashMap;
use tokio::runtime::current_thread::block_on_all;
#[derive(Debug)]
pub struct PostInfo {
@ -37,10 +38,16 @@ impl From<std::option::NoneError> for SiteError {
}
}
impl From<egg_mode::error::Error> for SiteError {
fn from(_: egg_mode::error::Error) -> SiteError {
SiteError {}
}
}
pub trait Site {
fn name(&self) -> &'static str;
fn is_supported(&mut self, url: &str) -> bool;
fn get_images(&mut self, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError>;
fn get_images(&mut self, user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError>;
}
pub struct Direct;
@ -86,7 +93,7 @@ impl Site for Direct {
Direct::TYPES.iter().any(|t| content_type == t)
}
fn get_images(&mut self, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
fn get_images(&mut self, _user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
let u = url.to_string();
Ok(Some(vec![PostInfo {
@ -100,7 +107,7 @@ impl Site for Direct {
}
}
pub struct e621 {
pub struct E621 {
show: regex::Regex,
data: regex::Regex,
@ -108,14 +115,14 @@ pub struct e621 {
}
#[derive(Deserialize)]
struct e621Post {
struct E621Post {
id: i32,
file_url: String,
preview_url: String,
file_ext: String,
}
impl e621 {
impl E621 {
pub fn new() -> Self {
Self {
show: regex::Regex::new(r"https?://(?P<host>e(?:621|926)\.net)/post/show/(?P<id>\d+)(?:/(?P<tags>.+))?").unwrap(),
@ -126,7 +133,7 @@ impl e621 {
}
}
impl Site for e621 {
impl Site for E621 {
fn name(&self) -> &'static str {
"e621"
}
@ -135,31 +142,133 @@ impl Site for e621 {
self.show.is_match(url) || self.data.is_match(url)
}
fn get_images(&mut self, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
fn get_images(&mut self, _user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
let endpoint = if self.show.is_match(url) {
let captures = self.show.captures(url).unwrap();
let id = &captures["id"];
format!("https://e621.net/post/show.json?id={}", id).to_string()
format!("https://e621.net/post/show.json?id={}", id)
} else {
let captures = self.data.captures(url).unwrap();
let md5 = &captures["md5"];
format!("https://e621.net/post/show.json?md5={}", md5).to_string()
format!("https://e621.net/post/show.json?md5={}", md5)
};
let resp: e621Post = self.client.get(&endpoint).send()?.json()?;
let resp: E621Post = self.client.get(&endpoint).send()?.json()?;
Ok(Some(vec![
PostInfo {
file_type: resp.file_ext,
url: resp.file_url,
thumb: resp.preview_url,
caption: format!("https://e621.net/post/show/{}", resp.id),
full_url: None,
message: None,
}
]))
Ok(Some(vec![PostInfo {
file_type: resp.file_ext,
url: resp.file_url,
thumb: resp.preview_url,
caption: format!("https://e621.net/post/show/{}", resp.id),
full_url: None,
message: None,
}]))
}
}
pub struct Twitter {
matcher: regex::Regex,
consumer: egg_mode::KeyPair,
token: egg_mode::Token,
}
impl Twitter {
pub fn new(
consumer_key: String,
consumer_secret: String, /*, access_token: String, access_token_secret: String*/
) -> Self {
use egg_mode::KeyPair;
let consumer = KeyPair::new(consumer_key, consumer_secret);
let token = block_on_all(egg_mode::bearer_token(&consumer)).unwrap();
Self {
matcher: regex::Regex::new(
r"https://(?:mobile\.)?twitter.com/(?:\w+)/status/(?P<id>\d+)",
)
.unwrap(),
consumer,
token,
}
}
}
impl Site for Twitter {
fn name(&self) -> &'static str {
"Twitter"
}
fn is_supported(&mut self, url: &str) -> bool {
self.matcher.is_match(url)
}
fn get_images(&mut self, user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
use pickledb::{PickleDb, PickleDbDumpPolicy, SerializationMethod};
let captures = self.matcher.captures(url).unwrap();
let id = captures["id"].to_owned().parse::<u64>().unwrap();
log::trace!(
"Attempting to find saved credentials for {}",
&format!("credentials:{}", user_id)
);
let db_path = std::env::var("TWITTER_DATABASE").expect("Missing Twitter database path");
let db = PickleDb::load(
db_path.clone(),
PickleDbDumpPolicy::AutoDump,
SerializationMethod::Json,
)
.unwrap_or_else(|_| {
PickleDb::new(
db_path,
PickleDbDumpPolicy::AutoDump,
SerializationMethod::Json,
)
});
let saved: Option<(String, String)> = db.get(&format!("credentials:{}", user_id));
log::debug!("User saved Twitter credentials: {:?}", saved);
let token = match saved {
Some(token) => egg_mode::Token::Access {
consumer: self.consumer.clone(),
access: egg_mode::KeyPair::new(token.0, token.1),
},
_ => self.token.clone(),
};
log::debug!("token: {:?}", token);
let tweet = match block_on_all(egg_mode::tweet::show(id, &token)) {
Ok(tweet) => tweet.response,
Err(e) => return Err(e.into()),
};
let screen_name = tweet.user.unwrap().screen_name.to_owned();
let tweet_id = tweet.id;
let media = match tweet.extended_entities {
Some(entity) => entity.media,
None => return Ok(None),
};
let link = format!("https://twitter.com/{}/status/{}", screen_name, tweet_id);
Ok(Some(
media
.into_iter()
.map(|item| PostInfo {
file_type: get_file_ext(&item.media_url_https).unwrap().to_owned(),
url: item.media_url_https.clone(),
thumb: format!("{}:thumb", item.media_url_https.clone()),
caption: link.clone(),
full_url: None,
message: None,
})
.collect(),
))
}
}
@ -255,7 +364,7 @@ impl Site for FurAffinity {
|| url.contains("facdn.net/art/")
}
fn get_images(&mut self, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
fn get_images(&mut self, _user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
let image = if url.contains("facdn.net/art/") {
self.load_direct_url(url)
} else {
@ -333,7 +442,7 @@ impl Site for Mastodon {
true
}
fn get_images(&mut self, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
fn get_images(&mut self, _user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
let captures = self.matcher.captures(url).unwrap();
let base = captures["host"].to_owned();
@ -396,7 +505,7 @@ impl Site for Weasyl {
self.matcher.is_match(url)
}
fn get_images(&mut self, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
fn get_images(&mut self, _user_id: i32, url: &str) -> Result<Option<Vec<PostInfo>>, SiteError> {
let captures = self.matcher.captures(url).unwrap();
let sub_id = captures["id"].to_owned();

View File

@ -91,6 +91,57 @@ pub struct Chat {
pub chat_type: String,
}
#[derive(Debug, Deserialize)]
pub struct MessageEntity {
#[serde(rename = "type")]
pub entity_type: MessageEntityType,
pub offset: i32,
pub length: i32,
pub url: Option<String>,
pub user: Option<User>,
}
#[derive(Debug, PartialEq)]
pub enum MessageEntityType {
Mention,
Hashtag,
Cashtag,
BotCommand,
URL,
Email,
PhoneNumber,
Bold,
Italic,
Code,
Pre,
TextLink,
TextMention,
}
impl<'de> Deserialize<'de> for MessageEntityType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer<'de>
{
let s = String::deserialize(deserializer)?;
Ok(match s.as_str() {
"mention" => Self::Mention,
"hashtag" => Self::Hashtag,
"cashtag" => Self::Cashtag,
"bot_command" => Self::BotCommand,
"url" => Self::URL,
"email" => Self::Email,
"phone_number" => Self::PhoneNumber,
"bold" => Self::Bold,
"italic" => Self::Italic,
"code" => Self::Code,
"pre" => Self::Pre,
"text_link" => Self::TextLink,
"text_mention" => Self::TextMention,
_ => unimplemented!(),
})
}
}
#[derive(Debug, Deserialize)]
pub struct Message {
pub message_id: i32,
@ -98,6 +149,7 @@ pub struct Message {
pub chat: Chat,
pub text: Option<String>,
pub photo: Option<Vec<PhotoSize>>,
pub entities: Option<Vec<MessageEntity>>,
}
#[derive(Debug, Deserialize)]
@ -167,6 +219,12 @@ impl From<i64> for ChatID {
}
}
impl From<i32> for ChatID {
fn from(item: i32) -> Self {
ChatID::Identifier(item as i64)
}
}
impl From<String> for ChatID {
fn from(item: String) -> Self {
ChatID::Username(item)
@ -218,11 +276,36 @@ impl TelegramRequest for GetUpdates {
}
}
#[derive(Serialize, Debug)]
pub struct ForceReply {
pub force_reply: bool,
pub selective: bool,
}
impl Default for ForceReply {
fn default() -> Self {
Self {
force_reply: true,
selective: false,
}
}
}
#[derive(Serialize, Debug)]
#[serde(untagged)]
pub enum ReplyMarkup {
ForceReply(ForceReply),
}
/// SendMessage, well, sends a message.
#[derive(Serialize, Default, Debug)]
pub struct SendMessage {
pub chat_id: ChatID,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
}
impl TelegramRequest for SendMessage {