# -*- coding: utf-8 -*-
"""
Created on Dec 05, 2013

@author: Tyranic-Moron
"""

from CommandInterface import CommandInterface
from IRCMessage import IRCMessage
from IRCResponse import IRCResponse, ResponseType

from Utils import WebUtils


class Gif(CommandInterface):
    triggers = ['gif']
    help = 'gif - fetches a random gif posted during Desert Bus'
    
    def execute(self, message):
        """
        @type message: IRCMessage
        """
        url = "http://greywool.com/desertbus/7/gifs/random.php"

        webPage = WebUtils.fetchURL(url)

        link = webPage.body

        return IRCResponse(ResponseType.Say, u"Random DB gif: {0}".format(link), message.ReplyTo)

@@ -72,16 +72,30 @@
 oron%0A%22%22%22
+%0Aimport random
 %0A%0Afrom C
@@ -315,16 +315,25 @@
 p = 'gif
+ %5B%3Cyear%3E%5D
  - fetch
@@ -469,24 +469,25 @@
     %22%22%22%0A
+%0A
         
 url = %22h
@@ -478,19 +478,23 @@
         
-url
+baseURL
  = %22http
@@ -523,9 +523,10 @@
 bus/
-7
+%7B%7D
 /gif
@@ -538,16 +538,620 @@
 dom.php%22
+%0A        years = range(7, 9)%0A%0A        if len(message.ParameterList) %3E 0:%0A            invalid = u%22'%7B%7D' is not a valid year, valid years are %7B%7D to %7B%7D%22%5C%0A                .format(message.ParameterList%5B0%5D, years%5B0%5D, years%5B-1%5D)%0A            try:%0A                year = int(message.ParameterList%5B0%5D)%0A            except ValueError:%0A                return IRCResponse(ResponseType.Say, invalid, message.ReplyTo)%0A%0A            if year not in years:%0A                return IRCResponse(ResponseType.Say, invalid, message.ReplyTo)%0A        else:%0A            year = random.choice(years)%0A%0A        url = baseURL.format(year)
 %0A%0A      
@@ -1259,16 +1259,43 @@
 ype.Say,
+%0A                          
  u%22Rando
@@ -1302,16 +1302,17 @@
 m DB
+%7B%7D
  gif: %7B
-0
 %7D%22.f
@@ -1321,14 +1321,47 @@
 mat(
-link),
+year, link),%0A                          
  mes

add an optional year argument