Last active
October 22, 2020 03:14
-
-
Save celediel/287984a86ba9ac1b4c32 to your computer and use it in GitHub Desktop.
WhatCD plugin for Cinch - RIP WhatCD, you'll live on in our hearts forever
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding=utf-8 | |
require 'whatcd' # Gazelle API wrapper - gem install whatcd | |
require 'mash' # Cool hashes | |
# These are all very annoying. | |
# rubocop:disable Metrics/LineLength, Metrics/ClassLength, Metrics/CyclomaticComplexity | |
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize | |
module Cinch | |
module Plugins | |
# What.cd plugin for Cinch | |
class Wcd | |
include Cinch::Plugin | |
set :prefix, /^\./ | |
def initialize(*args) | |
super | |
@client = WhatCD::Client.new(config[:username], config[:password]) | |
@artist_url = 'https://what.cd/artist.php?id=' | |
end | |
match(/wcd artist(?: (.+))?/, method: :artist_search) | |
def artist_search(m, query) | |
# Fetch the data | |
puts query | |
begin | |
results = @client.fetch :artist, artistname: query | |
rescue WhatCD::APIError | |
m.reply('Nothing found!') | |
return | |
end | |
# Create the vars | |
name = results['name'] | |
url = "#{@artist_url}#{results['id']}" | |
tag = results['tags'] | |
tags = [] | |
tag.each { |i| tags << i['name'] } | |
# For iterating through the tags | |
# Max of 3, or total if less than 3 | |
tags.length >= 3 ? len = 3 : len = tags.length | |
output = "#{name} :: #{url} :: " | |
tags.first(len).each_with_index do |i, j| | |
j == len - 1 ? output << "#{i}" : output << "#{i}, " | |
end | |
output << ' ::' | |
m.reply(output) | |
end | |
match(/wcd top5(?: (.+))?/, method: :top5) | |
def top5(m) | |
# Fetch the data | |
begin | |
results = @client.fetch :top10, type: 'torrents', limit: 5 | |
rescue WhatCD::APIError | |
m.reply('Something went wrong!') | |
return | |
end | |
artists = [] | |
results[0]['results'].each { |i| artists << i['artist'] } | |
albums = [] | |
results[0]['results'].each { |i| albums << i['groupName'] } | |
results.length >= 5 ? len = 5 : len = results.length | |
output = 'Top 5 of today :: ' | |
len.times do |i| | |
output << "#{artists[i]} :: #{albums[i]}" | |
i == len - 1 ? output << '' : output << ' : : ' | |
end | |
m.reply(output) | |
end | |
# match(/wcd post-thread/, method: :post_thread) | |
def post_thread(m) | |
# Fetch the data | |
begin | |
results = @client.fetch :forum, type: 'viewthread', updatelastread: 1, threadid: 80428 | |
pages = results['pages'] | |
results = @client.fetch :forum, type: 'viewthread', updatelastread: 1, threadid: 80428, page: pages | |
rescue WhatCD::APIError | |
m.reply('Something went wrong!') | |
return | |
end | |
# dunno what else lol | |
end | |
end | |
end | |
end | |
# vim:tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab foldmethod=syntax: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment