Repository: sopel-irc/sopel

Issue:
[rss] Default fg/bg value shouldn't be empty string.
The code says fg and bg colours are optional as stated [here](https://github.com/embolalia/willie/blob/c627a84938696cadee52a19582aee2dbaafb563a/willie/modules/rss.py#L190-L191), but when I send command in a form of `.rss add #channel name url`, [it fills fg and bg with empty strings](https://github.com/embolalia/willie/blob/c627a84938696cadee52a19582aee2dbaafb563a/willie/modules/rss.py#L201-L202).

``` python
fg = int(match.group(4)) % 16 if match.group(4) else ''
bg = int(match.group(5)) % 16 if match.group(5) else ''
```

The table schema, however, allows tiny int or null, but string.

```
CREATE TABLE `rss_feeds` (
  `channel` text NOT NULL,
  `feed_name` text NOT NULL,
  `feed_url` text,
  `fg` tinyint(4) DEFAULT NULL,
  `bg` tinyint(4) DEFAULT NULL,
  `enabled` tinyint(1) DEFAULT '1',
  `article_title` text,
  `article_url` text,
  `published` text,
  `etag` text,
  `modified` text,
  PRIMARY KEY (`channel`(254),`feed_name`(254))
)
```

So the command without fg/bg, `.rss add #channel name url`, results in an error saying `OperationalError: (1366, "Incorrect integer value: '' for column 'fg' at row 1”)`.

I'm working on it, now.

[rss] Default fg/bg value shouldn't be empty string.
The code says fg and bg colours are optional as stated [here](https://github.com/embolalia/willie/blob/c627a84938696cadee52a19582aee2dbaafb563a/willie/modules/rss.py#L190-L191), but when I send command in a form of `.rss add #channel name url`, [it fills fg and bg with empty strings](https://github.com/embolalia/willie/blob/c627a84938696cadee52a19582aee2dbaafb563a/willie/modules/rss.py#L201-L202).

``` python
fg = int(match.group(4)) % 16 if match.group(4) else ''
bg = int(match.group(5)) % 16 if match.group(5) else ''
```

The table schema, however, allows tiny int or null, but string.

```
CREATE TABLE `rss_feeds` (
  `channel` text NOT NULL,
  `feed_name` text NOT NULL,
  `feed_url` text,
  `fg` tinyint(4) DEFAULT NULL,
  `bg` tinyint(4) DEFAULT NULL,
  `enabled` tinyint(1) DEFAULT '1',
  `article_title` text,
  `article_url` text,
  `published` text,
  `etag` text,
  `modified` text,
  PRIMARY KEY (`channel`(254),`feed_name`(254))
)
```

So the command without fg/bg, `.rss add #channel name url`, results in an error saying `OperationalError: (1366, "Incorrect integer value: '' for column 'fg' at row 1”)`.

I'm working on it, now.



Discussion:

Resolving patch:
diff --git a/willie/modules/rss.py b/willie/modules/rss.py
--- a/willie/modules/rss.py
+++ b/willie/modules/rss.py
@@ -115,12 +115,12 @@ def migrate_from_old_tables(bot, c):
                 '''.format(sub), (channel, site_name, site_url, fg, bg))
 
 
-def colour_text(text, fg, bg=''):
+def colour_text(text, fg=None, bg=None):
     """Given some text and fore/back colours, return a coloured text string."""
-    if fg == '':
+    if fg is None:
         return text
     else:
-        colour = '{0},{1}'.format(fg, bg) if bg != '' else fg
+        colour = '{0},{1}'.format(fg, bg) if bg is not None else fg
         return "\x03{0}{1}\x03".format(colour, text)
 
 
@@ -198,8 +198,8 @@ def _rss_add(self, bot, trigger, c):
         channel = match.group(1)
         feed_name = match.group(2).strip('"')
         feed_url = match.group(3)
-        fg = int(match.group(4)) % 16 if match.group(4) else ''
-        bg = int(match.group(5)) % 16 if match.group(5) else ''
+        fg = int(match.group(4)) % 16 if match.group(4) else None
+        bg = int(match.group(5)) % 16 if match.group(5) else None
 
         c.execute('''
             SELECT * FROM rss_feeds WHERE channel = {0} AND feed_name = {0}


Test patch: