init
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
public class Room
|
||||
{
|
||||
public string internalID { get; private set; } = "";
|
||||
public string name { get; private set; } = "";
|
||||
public List<string> users { get; private set; } = new List<string>();
|
||||
|
||||
public Room(string internalID)
|
||||
{
|
||||
this.internalID = internalID;
|
||||
}
|
||||
|
||||
public async Task GetName()
|
||||
{
|
||||
// https://rawrly.com/_matrix/client/r0/rooms/!IhFsOrvvOXcSaoMqDB:rawrly.com/state/m.room.name
|
||||
string result = await Query.Get("_matrix/client/r0/rooms/" + internalID + "/state/m.room.name", true);
|
||||
if (result != null)
|
||||
{
|
||||
JObject json = JObject.Parse(result);
|
||||
name = (string) json["name"];
|
||||
}
|
||||
}
|
||||
|
||||
public void GetSpaceName()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task GetMembers()
|
||||
{
|
||||
// https://rawrly.com/_matrix/client/r0/rooms/!IhFsOrvvOXcSaoMqDB:rawrly.com/members
|
||||
string at = "";
|
||||
while (true)
|
||||
{
|
||||
Dictionary<string, string> extraParameters = new Dictionary<string, string>();
|
||||
if (at != "")
|
||||
{
|
||||
extraParameters.Add("at", at);
|
||||
}
|
||||
extraParameters.Add("membership", "join");
|
||||
|
||||
string result = await Query.Get($"_matrix/client/r0/rooms/{internalID}/members", true, extraParameters);
|
||||
|
||||
JObject json = JObject.Parse(result);
|
||||
if (json.ContainsKey("chunk"))
|
||||
{
|
||||
foreach (JObject member in (JArray) json["chunk"])
|
||||
{
|
||||
string userID = (string) member["user_id"];
|
||||
if (!users.Contains(userID))
|
||||
users.Add(userID);
|
||||
}
|
||||
}
|
||||
|
||||
// if (json.ContainsKey(""))
|
||||
// (Not sure how pagination is handled, seems to just send everything for this one?)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task KickT2Bots(bool dryRun)
|
||||
{
|
||||
// Clear members list
|
||||
users.Clear();
|
||||
await GetMembers();
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
if (user.EndsWith(":t2bot.io"))
|
||||
{
|
||||
if (dryRun)
|
||||
Console.WriteLine($"Would kick: {user}");
|
||||
else
|
||||
{
|
||||
// KICK code
|
||||
Console.WriteLine($"Kicking: {user}");
|
||||
JObject kickData = new JObject();
|
||||
kickData.Add("user_id", user);
|
||||
string result = await Query.Post($"_matrix/client/v3/rooms/{internalID}/kick", true, kickData.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user