Example #1
0
        public async Task AddToBanList( DirtbagSettings conn, List<BannedEntity> list ) {
            using ( var handler = new WebRequestHandler() ) {
                handler.ServerCertificateValidationCallback = ValidateCert;
                using ( var client = new HttpClient( handler ) ) {
                    string auth = Convert.ToBase64String( Encoding.ASCII.GetBytes( $"{conn.DirtbagUsername}:{conn.DirtbagPassword}" ) );
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", auth );

                    var response = await client.PostAsJsonAsync( conn.DirtbagUrl + BAN_LIST_ROOT_ENDPOINT, list );
                    if ( !response.IsSuccessStatusCode ) {
                        throw new HttpRequestException( response.StatusCode + ": " + await response.Content.ReadAsStringAsync() );
                    }
                }
            }
        }
Example #2
0
        public async Task<bool> UpdateBotSettings(DirtbagSettings settings, string subName) {
            using ( SqlConnection conn = new SqlConnection( connstring ) ) {
                string query = @"
update Subreddits
set DirtbagUrl = @DirtbagUrl,
DirtbagUsername = @DirtbagUsername,
DirtbagPassword = @DirtbagPassword
WHERE
SubName = @subName
";
                await conn.ExecuteAsync( query, new { settings.DirtbagUrl, settings.DirtbagUsername, settings.DirtbagPassword, subName } );
                return true;
            }
        }
Example #3
0
        public async Task<bool> RemoveFromBanList( DirtbagSettings conn, int id, string modName, string subreddit ) {
            using ( var handler = new WebRequestHandler() ) {
                handler.ServerCertificateValidationCallback = ValidateCert;
                using ( var client = new HttpClient( handler ) ) {
                    string auth = Convert.ToBase64String( Encoding.ASCII.GetBytes( $"{conn.DirtbagUsername}:{conn.DirtbagPassword}" ) );
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", auth );

                    var response = await client.DeleteAsync( string.Format( conn.DirtbagUrl + REMOVE_BAN_ENDPOINT, subreddit, id, modName ) );

                    if ( response.IsSuccessStatusCode )
                        return true;

                    return false;
                }
            }
        }
Example #4
0
        public async Task<IEnumerable<BannedEntity>> GetBanList( DirtbagSettings conn, string subreddit ) {
            using ( var handler = new WebRequestHandler() ) {
                handler.ServerCertificateValidationCallback = ValidateCert;
                using ( var client = new HttpClient( handler ) ) {
                    string auth = Convert.ToBase64String( Encoding.ASCII.GetBytes( $"{conn.DirtbagUsername}:{conn.DirtbagPassword}" ) );
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", auth );

                    var response = await client.GetAsync( string.Format( conn.DirtbagUrl + BAN_LIST_ENDPOINT, subreddit ) );

                    if ( !response.IsSuccessStatusCode )
                        throw new HttpRequestException( response.StatusCode + ": " + await response.Content.ReadAsStringAsync() );

                    string responseString = await response.Content.ReadAsStringAsync();

                    IEnumerable<BannedEntity> toReturn = JsonConvert.DeserializeObject<IEnumerable<BannedEntity>>( responseString );
                    return toReturn;
                }
            }
        }
Example #5
0
        public async Task UpdateBanReason( DirtbagSettings conn, string subName, int id, string reason, string modname ) {
            using ( var handler = new WebRequestHandler() ) {
                handler.ServerCertificateValidationCallback = ValidateCert;
                using ( var client = new HttpClient( handler ) ) {
                    string auth = Convert.ToBase64String( Encoding.ASCII.GetBytes( $"{conn.DirtbagUsername}:{conn.DirtbagPassword}" ) );
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", auth );

                    var response = await client.PutAsJsonAsync( string.Format( conn.DirtbagUrl + UPDATE_BAN_REASON_ENDPOINT, subName, id, modname ), reason );
                    if ( !response.IsSuccessStatusCode ) {
                        throw new HttpRequestException( response.StatusCode + ": " + await response.Content.ReadAsStringAsync() );
                    }
                }
            }

        }
Example #6
0
 public Task<bool> TestConnection( DirtbagSettings botSettings, string subreddit ) {
     return TestConnection( botSettings.DirtbagUrl, botSettings.DirtbagUsername, botSettings.DirtbagPassword, subreddit );
 }