This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSVTools.cs
70 lines (60 loc) · 2.08 KB
/
SVTools.cs
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
using SpookVooper.Api.Entities;
using SpookVooper.Api.Entities.Groups;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace CocaBot_Valour
{
public static class SVTools
{
public static async Task<string> SVIDToName(string SVID)
{
bool isgroup = SVID[0].Equals('g');
bool isuser = SVID[0].Equals('u');
if (!isgroup & !isuser) { return null; }
if (isuser ^ isgroup)
{
if (isuser)
{
User user = new(SVID);
return await user.GetUsernameAsync();
}
Group group = new(SVID);
return await @group.GetNameAsync();
}
throw new Exception("A SVID cannot both have 'g-' and 'u-' at the 2 starting letters of a string!");
}
public static async Task<Dictionary<string, string>> NameToSVID(string name)
{
Dictionary<string, string> svids = new Dictionary<string, string>();
string gsvid = await Group.GetSVIDFromNameAsync(name);
string usvid = await User.GetSVIDFromUsernameAsync(name);
bool isgroup = !gsvid[0].Equals('g');
bool isuser = !usvid[0].Equals('u');
if (!isgroup && !isuser)
{
return null;
}
if (isgroup && isuser)
{
svids.Add("User", usvid);
svids.Add("Group", gsvid);
}
else if (isuser)
{
svids.Add("User", usvid);
}
else
{
svids.Add("Group", gsvid);
}
return svids;
}
public static async Task<bool> IsName(string name)
{
string gsvid = await Group.GetSVIDFromNameAsync(name);
string usvid = await User.GetSVIDFromUsernameAsync(name);
return gsvid.Contains("HTTP Error: NotFound; Could not find") || usvid.Contains("HTTP Error: NotFound; Could not find");
}
}
}