Commit f1b96fc1 authored by Robert Rudman's avatar Robert Rudman

Implement functionality to add room owners. Add Gemmy as a room owner to burn...

Implement functionality to add room owners. Add Gemmy as a room owner to burn room. Add links to close view and opened questions in the tag
parent 26144632
......@@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Rodgort.Data;
using Rodgort.Data.Constants;
using Rodgort.Data.Tables;
......@@ -127,7 +128,10 @@ namespace Rodgort.Services
else
await RenameObservationRoom(roomId, metaPostUrl, tag);
var burninationMessage = $"The burnination of [tag:{tag}] has STARTED! [Meta post]({metaPostUrl}). [Burnination progress room](https://chat.stackoverflow.com/rooms/{roomId}).";
var closeQueueLink = UrlTools.BuildUrl("https://stackoverflow.com/review/close/", new Dictionary<string, string> { { "filter-tags", tag } });
var openQuestionsLink = UrlTools.BuildUrl("https://stackoverflow.com/search", new Dictionary<string, string> { { "q", $"[{tag}] is:q closed:no" } });
var burninationMessage = $"The burnination of [tag:{tag}] has STARTED! [Close Queue]({closeQueueLink}) - [Open questions]({openQuestionsLink}) - [Meta post]({metaPostUrl}) - [Burn room](https://chat.stackoverflow.com/rooms/{roomId}).";
await _chatClient.SendMessageAndPin(ChatSite.StackOverflow, ChatRooms.TROGDOR, burninationMessage);
}
......@@ -141,6 +145,8 @@ namespace Rodgort.Services
var roomName = $"Burnination progress for the [{tag}] tag";
var roomId = await _chatClient.CreateRoom(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, roomName, metaPostUrl, new[] { tag });
await _chatClient.AddRoomOwner(ChatSite.StackOverflow, roomId, ChatUserIds.GEMMY);
var gemmyMessage = $"@Gemmy start tag [{tag}] {roomId} https://chat.stackoverflow.com/rooms/{roomId}";
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, gemmyMessage);
......@@ -168,6 +174,7 @@ namespace Rodgort.Services
var roomName = $"Observation room for [{tag}] burnination";
var roomId = await _chatClient.CreateRoom(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, roomName, metaPostUrl, new[] { tag });
await _chatClient.AddRoomOwner(ChatSite.StackOverflow, roomId, ChatUserIds.GEMMY);
await _chatClient.SendMessageAndPin(ChatSite.StackOverflow, roomId, $"[Rodgort tag progress](https://rodgort.sobotics.org/progress?metaQuestionId={metaQuestionId})");
......
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Rodgort.Utilities
{
public class UrlTools
{
public static string BuildUrl(string url, Dictionary<string, string> queryArgs)
{
if (!queryArgs.Any())
return url;
var queryString = HttpUtility.ParseQueryString(string.Empty);
foreach (var queryArg in queryArgs)
queryString.Add(queryArg.Key, queryArg.Value);
return $"{url}?{queryString}";
}
}
}
......@@ -133,6 +133,23 @@ namespace StackExchangeChat
}, Task.Delay(TimeSpan.FromSeconds(5)));
}
public async Task AddRoomOwner(ChatSite chatSite, int roomId, int userId)
{
await ThrottlingUtils.Throttle(ChatThrottleGroups.WebRequestThrottle, async () =>
{
var fkey = (await _siteAuthenticator.GetRoomDetails(chatSite, roomId)).FKey;
await _siteAuthenticator.AuthenticateClient(_httpClient, chatSite);
await _httpClient.PostAsync($"https://{chatSite.ChatDomain}/rooms/setuseraccess/${roomId}",
new FormUrlEncodedContent(
new Dictionary<string, string>
{
{"fkey", fkey},
{"userAccess", "owner"},
{"aclUserId", userId.ToString()},
}));
});
}
public IObservable<ChatEvent> SubscribeToEvents(ChatSite chatSite, int roomId)
{
return Observable.Create<ChatEvent>(async observer =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment