Dad   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 18
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 9 9 2
A post_init() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import urllib2
2
import json
3
from event import Event
4
try:
5
  from basemodule import BaseModule
6
except ImportError:
7
  from modules.basemodule import BaseModule
8 View Code Duplication
class Dad(BaseModule):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
  def post_init(self):
10
    d_event = Event("__.dad__")
11
12
    d_event.define(msg_definition="^\.dad")
13
    d_event.subscribe(self)
14
15
    self.bot.register_event(d_event, self)
16
17
  def handle(self, event):
18
    try:
19
      url = "https://icanhazdadjoke.com/"
20
      req = urllib2.Request(url, headers={'Accept' : "application/json", 'User-Agent' : "Magic Browser"})
21
      resp = urllib2.urlopen(req)
22
      j = json.loads(resp.read())
23
      self.say(event.channel, j['joke'])
24
    except:
25
      pass
26