<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using CSharpTradeOffers.Web;

namespace CSharpTradeOffers.Community
{
    /// <summary>
    /// Handles commmunity related tasks
    /// </summary>
    public class CommunityHandler
    {
        private readonly Web.Web _web = new Web.Web(new SteamWebRequestHandler());

        private const string BaseCommunityUrl = "https://steamcommunity.com/";
        private const string TopicUrl = BaseCommunityUrl + "forum/{0}/General/";
        private const string CommentUrl = BaseCommunityUrl + "comment/ForumTopic/delete/{0}/{1}/";

        private readonly Account _account;

        public CommunityHandler(Account account)
        {
            _account = account;
        }


        public GetTopicsHtmlResult GetTopicsHtml(ulong forumId, ulong start, ulong count)
        {
            string url = string.Format(TopicUrl, forumId) + "render/0/";

            var data = new Dictionary<string, string>
            {
                {"start", start.ToString()},
                {"count", count.ToString()}
            };

            return _web.Fetch(url, "POST", data, _account.AuthContainer).DeserializeJson<GetTopicsHtmlResult>();
        }

        /// <summary>
        /// Posts a comment to the specified profile.
        /// </summary>
        /// <param name="steamId">The SteamId64 of the profile to post to.</param>
        /// <param name="comment">The comment text.</param>
        /// <param name="Account.Account.AuthContainer">Auth Cookies MUST be passed here, the function will fail if not.</param>
        /// <returns>A CommentResponse object.</returns>
        public CommentResponse PostComment(ulong steamId, string comment)
        {
            string url = "https://steamcommunity.com/comment/Profile/post/" + steamId + "/-1/";

            string sessionid =
                (from Cookie cookie in _account.AuthContainer.GetCookies(new Uri("https://steamcommunity.com"))
                    where cookie.Name == "sessionid"
                    select cookie.Value).FirstOrDefault();

            var data = new Dictionary<string, string>
            {
                {"comment", comment},
                {"sessionid", sessionid}
            };

            return
                _web.Fetch(url, "POST", data, _account.AuthContainer, true, url.Substring(0, url.Length - 3))
                    .DeserializeJson<CommentResponse>();
        }
        
        /// <summary>
        /// Posts an announcement to the specified group.
        /// </summary>
        /// <param name="groupName">Groupname of the steam group.</param>
        /// <param name="headLine">The headline of the announcement.</param>
        /// <param name="body">The body of the announcement.</param>
        /// <returns>no return</returns>
        public void GroupAnnounce(string groupName, string headLine, string body)
        {
            string url = "http://steamcommunity.com/groups/" + groupName + "/announcements";

            string sessionid =
                (from Cookie cookie in _account.AuthContainer.GetCookies(new Uri("https://steamcommunity.com"))
                 where cookie.Name == "sessionid"
                 select cookie.Value).FirstOrDefault();

            var data = new Dictionary<string, string>
            {
                {"sessionID", sessionid},
                {"action", "post"},
                {"headline", headLine},
                {"body", body},
                {"languages[0][headline]", headLine},
                {"languages[0][body]", body}
            };

            for (int i = 1; i <= 26; i++)
            {
                data.Add("languages[" + i + "][headline]", "");
                data.Add("languages[" + i + "][body]", "");
                data.Add("languages[" + i + "][updated]", "0");
            }

            _web.Fetch(url, "POST", data, _account.AuthContainer, true, url + "/create");
        }

        /// <summary>
        /// Posts an event to the specified group.
        /// </summary>
        /// <param name="groupName">Groupname of the steam group.</param>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="eventNotes">The notes of the event.</param>
        /// <param name="timeChoice">"quick" which means now, or "specific" which means will start at the given date/time.</param>
        /// <param name="startMinute">The minute of the event date. EX: 30</param>
        /// <param name="startHour">The hour of the event date. EX: 10</param>
        /// <param name="startDate">The date of the event. MM/DD/YY EX: 12/20/18</param>
        /// <param name="startAMPM">AM or PM of the event date.</param>
        /// <param name="serverPassword">Password to the server.</param>
        /// <param name="serverIP">Ip of the server.</param>
        /// <param name="appID">The game associated with the event.</param>
        /// <returns>no return</returns>
        public void GroupEvent(string groupName, string eventName, string eventNotes, string eventType, string timeChoice = "quick", string startMinute = "00", string startHour = "12", string startDate = "MM/DD/YY", string startAMPM = "PM", string serverPassword = "", string serverIP = "", string appID = "")
        {
            string url = "http://steamcommunity.com/groups/" + groupName + "/eventEdit";

            string sessionid =
                (from Cookie cookie in _account.AuthContainer.GetCookies(new Uri("https://steamcommunity.com"))
                 where cookie.Name == "sessionid"
                 select cookie.Value).FirstOrDefault();

            var data = new Dictionary<string, string>
            {
                {"sessionid", sessionid},
                {"tzOffset", "-18000"},
                {"type", eventType}, // What type of event? BroadcastEvent, Chat, etc
                {"timeChoice", timeChoice}, // "quick" which means now, or "specific" which means will start at the given date/time
                {"startMinute", startMinute},
                {"startHour", startHour},
                {"startDate", startDate},
                {"startAMPM", startAMPM},
                {"serverPassword", serverPassword},
                {"serverIP", serverIP},
                {"name", eventName}, // Title of the event
                {"notes", eventNotes}, // Notes of the event
                {"eventQuickTime", "now"},
                {"appID", appID}, // The game you want the event associated with
                {"action", "newEvent"}
            };

            _web.Fetch(url, "POST", data, _account.AuthContainer, true, url);
        }
<commit_msg>Now takes strongly typed arguments<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using CSharpTradeOffers.Web;

namespace CSharpTradeOffers.Community
{
    /// <summary>
    /// Handles commmunity related tasks
    /// </summary>
    public class CommunityHandler
    {
        private readonly Web.Web _web = new Web.Web(new SteamWebRequestHandler());

        private const string BaseCommunityUrl = "https://steamcommunity.com/";
        private const string TopicUrl = BaseCommunityUrl + "forum/{0}/General/";
        private const string CommentUrl = BaseCommunityUrl + "comment/ForumTopic/delete/{0}/{1}/";

        private readonly Account _account;

        public CommunityHandler(Account account)
        {
            _account = account;
        }


        public GetTopicsHtmlResult GetTopicsHtml(ulong forumId, ulong start, ulong count)
        {
            string url = string.Format(TopicUrl, forumId) + "render/0/";

            var data = new Dictionary<string, string>
            {
                {"start", start.ToString()},
                {"count", count.ToString()}
            };

            return _web.Fetch(url, "POST", data, _account.AuthContainer).DeserializeJson<GetTopicsHtmlResult>();
        }

        /// <summary>
        /// Posts a comment to the specified profile.
        /// </summary>
        /// <param name="steamId">The SteamId64 of the profile to post to.</param>
        /// <param name="comment">The comment text.</param>
        /// <param name="Account.Account.AuthContainer">Auth Cookies MUST be passed here, the function will fail if not.</param>
        /// <returns>A CommentResponse object.</returns>
        public CommentResponse PostComment(ulong steamId, string comment)
        {
            string url = "https://steamcommunity.com/comment/Profile/post/" + steamId + "/-1/";

            string sessionid =
                (from Cookie cookie in _account.AuthContainer.GetCookies(new Uri("https://steamcommunity.com"))
                    where cookie.Name == "sessionid"
                    select cookie.Value).FirstOrDefault();

            var data = new Dictionary<string, string>
            {
                {"comment", comment},
                {"sessionid", sessionid}
            };

            return
                _web.Fetch(url, "POST", data, _account.AuthContainer, true, url.Substring(0, url.Length - 3))
                    .DeserializeJson<CommentResponse>();
        }
        
        /// <summary>
        /// Posts an announcement to the specified group.
        /// </summary>
        /// <param name="groupName">Groupname of the steam group.</param>
        /// <param name="headLine">The headline of the announcement.</param>
        /// <param name="body">The body of the announcement.</param>
        /// <returns>no return</returns>
        public void GroupAnnounce(string groupName, string headLine, string body)
        {
            string url = "http://steamcommunity.com/groups/" + groupName + "/announcements";

            string sessionid =
                (from Cookie cookie in _account.AuthContainer.GetCookies(new Uri("https://steamcommunity.com"))
                 where cookie.Name == "sessionid"
                 select cookie.Value).FirstOrDefault();

            var data = new Dictionary<string, string>
            {
                {"sessionID", sessionid},
                {"action", "post"},
                {"headline", headLine},
                {"body", body},
                {"languages[0][headline]", headLine},
                {"languages[0][body]", body}
            };

            for (int i = 1; i <= 26; i++)
            {
                data.Add("languages[" + i + "][headline]", "");
                data.Add("languages[" + i + "][body]", "");
                data.Add("languages[" + i + "][updated]", "0");
            }

            _web.Fetch(url, "POST", data, _account.AuthContainer, true, url + "/create");
        }

        /// <summary>
        /// Posts an event to the specified group.
        /// </summary>
        /// <param name="groupName">Groupname of the steam group.</param>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="eventNotes">The notes of the event.</param>
        /// <param name="timeChoice">"quick" which means now, or "specific" which means will start at the given date/time.</param>
        /// <param name="startMinute">The minute of the event date. EX: 30</param>
        /// <param name="startHour">The hour of the event date. EX: 10</param>
        /// <param name="startDate">The date of the event. MM/DD/YY EX: 12/20/18</param>
        /// <param name="startAMPM">AM or PM of the event date.</param>
        /// <param name="serverPassword">Password to the server.</param>
        /// <param name="serverIP">Ip of the server.</param>
        /// <param name="appID">The game associated with the event.</param>
        /// <returns>no return</returns>
        public void GroupEvent(string groupName, string eventName, string eventNotes, string eventType, DateTime startDateAndTime,
                               string timeChoice = "quick", string serverPassword = "", IPAddress serverAddress = null, int appId = -1, int timezoneOffset = -18000)
        {
            string url = "http://steamcommunity.com/groups/" + groupName + "/eventEdit";

            string sessionid =
                (from Cookie cookie in _account.AuthContainer.GetCookies(new Uri("https://steamcommunity.com"))
                 where cookie.Name == "sessionid"
                 select cookie.Value).FirstOrDefault();

            var data = new Dictionary<string, string>
            {
                {"sessionid", sessionid},
                {"tzOffset", timezoneOffset.ToString()},
                {"type", eventType}, // What type of event? BroadcastEvent, Chat, etc
                {"timeChoice", timeChoice}, // "quick" which means now, or "specific" which means will start at the given date/time
                {"startMinute", startDateAndTime.TimeOfDay.Minutes.ToString()},
                {"startHour", startDateAndTime.TimeOfDay.Hours.ToString()},
                {"startDate", startDateAndTime.ToString("MM/DD/YY")},
                {"startAMPM", startDateAndTime.TimeOfDay.Hours >= 12 ? "PM" : "AM" },
                {"serverPassword", serverPassword},
                {"serverIP", serverAddress == null ? "" : serverAddress.ToString()},
                {"name", eventName}, // Title of the event
                {"notes", eventNotes}, // Notes of the event
                {"eventQuickTime", "now"},
                {"appID", appId == -1 ? "" : appId.ToString()}, // The game you want the event associated with
                {"action", "newEvent"}
            };

            _web.Fetch(url, "POST", data, _account.AuthContainer, true, url);
        }

{'fraction_non_alphanumeric': 0.13521436423598387, 'fraction_numerical': 0.004983510443385856, 'mean_word_length': 1.9945139346061005, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 112, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '520885', 'n_tokens_mistral': 3639, 'n_tokens_neox': 3436, 'n_words': 972}