1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use crate::prelude::*;
pub struct Reports {
modio: Modio,
}
impl Reports {
pub(crate) fn new(modio: Modio) -> Self {
Self { modio }
}
pub async fn submit(self, report: Report) -> Result<()> {
self.modio
.request(Route::SubmitReport)
.form(&report)
.send::<Message>()
.await?;
Ok(())
}
}
pub struct Report {
pub name: String,
pub contact: Option<String>,
pub summary: String,
pub kind: ReportType,
pub resource: Resource,
}
pub enum ReportType {
Generic,
DMCA,
NotWorking,
RudeContent,
IllegalContent,
StolenContent,
FalseInformation,
Other,
}
pub enum Resource {
Game(u32),
Mod(u32),
User(u32),
}
impl Report {
pub fn new<S: Into<String>>(
name: S,
contact: Option<S>,
summary: S,
kind: ReportType,
resource: Resource,
) -> Self {
Self {
name: name.into(),
contact: contact.map(Into::into),
summary: summary.into(),
kind,
resource,
}
}
}
#[doc(hidden)]
impl serde::ser::Serialize for Report {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
use serde::ser::SerializeMap;
let (resource, id) = match self.resource {
Resource::Game(id) => ("games", id),
Resource::Mod(id) => ("mods", id),
Resource::User(id) => ("users", id),
};
let _type = match self.kind {
ReportType::Generic => 0,
ReportType::DMCA => 1,
ReportType::NotWorking => 2,
ReportType::RudeContent => 3,
ReportType::IllegalContent => 4,
ReportType::StolenContent => 5,
ReportType::FalseInformation => 6,
ReportType::Other => 7,
};
let len = if self.contact.is_some() { 6 } else { 5 };
let mut map = serializer.serialize_map(Some(len))?;
if let Some(ref c) = self.contact {
map.serialize_entry("contact", c)?;
}
map.serialize_entry("resource", resource)?;
map.serialize_entry("id", &id)?;
map.serialize_entry("type", &_type)?;
map.serialize_entry("name", &self.name)?;
map.serialize_entry("summary", &self.summary)?;
map.end()
}
}