GithubHelp home page GithubHelp logo

deltabot's Introduction

Deprecated

This version of DeltaBot has been deprecated. For the newest version, please see http://github.com/PixelOrange/MARS.

DeltaBot

DeltaBot is a score keeping reddit bot originally designed for /r/changemyview. If you are thinking about using this code for your own subreddit, or any other purpose, we advise that you use a token that makes sense to you. The delta is an appropriate symbol that was chosen for /r/changemyview because it is often used to represent change.

This bot works by reading a subreddit and looking for specific tokens that denote that a point should be awarded. If it finds one, it acts accordingly by carrying out various jobs that can be found at http://www.reddit.com/r/changemyview/wiki/deltabot.

Usage

  1. Make sure you have Python and PRAW installed.
  2. Create the file config.json and fill in the appropriate fields using config.json.example as a template.
  3. Linux/Mac users: Run runbot.sh. Windows users: Run winrun.bat. CLI: Type python deltabot from the root folder of the program.

Make sure whatever account you're using to run the bot is a moderator of your subreddit and has permission to edit flair and the wiki.

Contribute

If you're a developer visit the developer subreddit /r/DeltaBot

Check out requirements_doc.txt to get an idea of what DeltaBot needs to do. To see new features that have not been implemented yet, check the Issues page.

Join us on IRC! (Snoonet #DeltaBot)

deltabot's People

Contributors

acebulf avatar alexames avatar amorde avatar chillee avatar chrisuehlinger avatar dubslow avatar gvx avatar jayelm avatar lolletsoc avatar pixelorange avatar projectdelphai avatar randompoison avatar snorrrlax avatar yaworsw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deltabot's Issues

Important: Several bugs

Importance: High


Remove line 228:
message.mark_as_read()

This is causing the mail function to fail.


Swap position of lines 301 and 302 so they are:
self.scan_inbox()
self.scan_comments()

Mail should be read before comments because any issue that causes the bot to crash in the comments will prevent the inbox from being read. The inbox should never have any crash issues since the data being provided is curated by the mod submitting the content.


Change line 197 to:
for comment in self.subreddit.get_comments(params={'before': self.before_id},limit=None):


points_already_awarded() is not functional. The only thing preventing this is the before_id check. If you send DeltaBot a PM to add a delta, it will give more than one. Both of the below options are available but are not complete. You MUST do testing after making this change or stuff will not work properly.

Change line 157 to:
if reply.author.lower == self.config.account['username'].lower:

Alternatively, change line 186 to:
if self.config.account['username'].lower() in comment.replies:

If you choose the alternate option, you can remove the points_already_awarded() function.


Line 170 is causing slow processing. Checking the parent before you've found a token is not efficient because it's doing extra API calls. Only check for a parent after you've found a delta.

Change lines 170-172 to:
if string_contains_token(comment.body, self.config.tokens):
parent = self.reddit.get_info(thing_id=comment.parent_id)
if parent.author.name is not self.config.account['username']:


Change all instances of "comment.name" to "comment.id". This should resolve the before_id errors.

Edit: It appears that this does change functionality but does not necessarily fix the issue. Now it's scanning too many rather than too few.


Importance: Low


Change line 277 to:
add_link = "\n\n* %s" % (comment_submission_title, comment_url)

Change line 282 to:
add_link = "\n\n* %s" % (comment_submission_title, comment_url)

Unbiased leaderboard

This is a continuation of issue #3 which I accidentally referenced in a commit.

The leaderboards should not be ordered alphabetically or any other unbiased way. For example, if Zebra had 5 deltas and then Alex got 5 deltas, Alex should not show up on the leaderboards before Zebra just because his name starts with an A. Instead, Zebra should stay at the top of the leaderboard until Alex passes him.

subreddit duplication

There's two different variables for the subreddit name that are used throughout the code:

self.config.subreddit

self.subreddit

Is there a particular reason this is coded this way or can we clean the code up to only use one or the other?

Also, there appears to be various letter casing bugs that I haven't been able to narrow down. When I launched the program with all lowercase words for my subreddit/username/password, it wouldn't scan comments. If I mirrored what's in reddit, it works fine.

Incorrect delta total on wiki user page

The delta totals are not correct on the wiki page for each user. It appears to either be pulling from the incorrect location or is being defeated by Reddit's API limitations.

Combine functions

The below functions can be simplified.


Current functions:

def get_first_int(string):
    """ Returns the first integer in the string"""
    match = re.search(u'(\d+)', string)
    return int(match.group()) if match else 0


def flair_sorter(dic):
    """ Get numeric value from flair. """
    num = dic[u'flair_text']
    if num:
        return get_first_int(num)
    else:
        return 0

Simplified function:

def previous_flair(parent):
  # Gets the previous number of deltas
  num = dic[u'flair_text']
  match = re.search('(u\')(\d+)', num)
  if match:
    return int(match.group(2)) + 1
  else:
    return 1

PixelBot Code (for reference only)

def previous_flair(parent):
  # Gets the previous number of deltas
  old_flair = subreddit.get_flair(parent.author)
  old_flair = str(old_flair)
  #print old_flair # Show the full flair
  match = re.search('(u\')(\d+)', old_flair)
  if match:
    return int(match.group(2)) + 1
  else:
    return 1

Force add doesn't work if deltabot has already replied

Force add doesn't work if deltabot has already replied, regardless of what that reply was.

  • Force add should not work if it has already given a delta.
  • Force add should work if it has not given a delta for any reason and has replied as to what that reason is. Instead, the previous comment should be removed and the force add should proceed.

"Delta queue" mod tool.

(To be hosted at /r/changemyview/wiki/deltaqueue).

Every delta comment will be added to this page (oldest at the top, newest underneath).

Because deltabot can only tell whether the delta has been given or not rather than should have been given or not, this mod tool could really help keep up the quality of CMV.

The idea is a wiki page where DeltaBot would post links to the comments that included deltas, so we could easily check whether they were genuine or not. I was also thinking that this list could contain some kind of "approve" and "remove" buttons next to each link, so that deltabot knows if we think it was okay or not, and removes it from the wiki page once action has been taken.

The approve button could be a ready made PM to DeltaBot that it recognises as confirmation. Equally, a "remove" button would be a PM to DeltaBot which it recognises as a command to remove the confirmation message along with the delta from the user flair/wiki page. A "request" button could be used for when the delta isn't straight forward abuse, but just needs more reasoning (perhaps this isn't necessary now with 100 character limit, but I have still seen long comments that don't explain how their view has changed)..

The layout would be something like:

Where the link to the comment has ?context=1 in the url.

To clarify, the deltas are already awarded by DeltaBot before they are linked to the wiki page. DeltaBot doesn't wait for our approval, but acts on our disapproval.

Refactoring and testing DeltaBot

Hey! So I've been talking with PixelOrange about making this project easier to test. Given that many people are coming and going on this project, I think testing would be a great way to make sure new contributors don't accidentally step on old code or break something that was written a long time ago.

If you are currently working on adding a feature, that's fine, but try to follow these principles as much as possible:

-Write pure functions: If given the same input two times, the function should give the same output both times.
-If you have to make calls to praw, do them higher up and then pass the results into your new function.
-Don't log inside of your functions: rather, return a variable containing what you would have logged, along with the result of the function. (this is less important)

Here's a list of the pure and impure functions with their side effects.

Pure:
get_first_int
flair_sorter
skippable_line
str_contains_token
markdown_to_scoreboard
scoreboard_to_markdown
string_matches_message
is_comment_too_short
scan_mod_mail

Impure:
write_saved_id(uses logging and file I/O)
read_saved_id(uses logging and file I/O)
init(logging, praw calls)
send_first_time_message(praw calls)
get_message(random numbers)
award_points(logging, calls other impure functions)
get_this_months_scoreboard(praw calls)
update_monthly_scoreboard(logging, praw calls)
adjust_point_flair(praw calls)
already_replied(praw calls)
is_parent_commenter_author(praw calls)
points_already_awarded_to_ancestor(praw calls)
scan_comment(logging, praw calls)
scan_comments(logging, praw calls, calls to impure functions)
command_add(praw calls)
is_moderator(praw calls)
scan_message(logging, praw calls, system calls)
rescan_comment(praw calls)
rescan_comments(praw calls, calls to impure functions)
scan_comment_reply(logging, praw calls, calls to impure functions)
scan_inbox(logging, praw calls, calls to impure functions)
update_scoreboard(logging, praw calls, time sensitive)
get_top_ten_scores(praw calls)
get_top_ten_scores_this_month(praw calls, time sensitive)
update_wiki_tracker(logging, praw calls)
update_wiki_tracker(logging, praw calls, calls to impure functions)
go(logging, praw calls, calls to impure functions)

We don't need to purify every function, but if we can move all the side effects up to go(), init() or other high-up functions, it will make everything else MUCH easier to test.

Ideally, I'd like to pass scan_comments() a list of comments and other data, and get back a list of output actions that need to be performed. In the meantime, if someone could get a unit testing library set up to test the pure functions, that'd be awesome.

"This delta is currently disallowed ... If you edit this in, replying to my comment will make me rescan yours." - Making this DeltaBot comment a reality?

A while ago when I was asked for drafts of the distinguished comments DeltaBot would leave, this is what I wrote for when a comment doesn't have enough text (i.e no explanation):

"This delta is currently disallowed as your comment contains either no or little text. Please include an explanation for how /u/%s changed your view. If you edit this in, replying to my comment will make me rescan yours. Thank you."

It mentions that if a user edits their comment to include the explanation and then replies to DeltaBot's confirmation message, the bot will rescan that comment to see if it's now acceptable, and take the appropriate action. Unless someone has decided to write this into the script since I gave the message, I'm pretty sure this doesn't currently happen.

Perhaps it could be made a reality?

DeltaBot not properly detecting first-time-delta

DeltaBot is correctly giving users deltas and is correctly setting up their wiki pages. However, it seems to be having difficulty discerning when someone does not have a delta. The reason this is important is because we send first-time-delta awardees a message that gives some basic information about how the delta system works.

I suspect the issue is tied to the fact that we have a lot of different things altering flair and it's picking up on the css tag that many users already have.

If AutoModerator automatically tags each post with a "No OP replies yet" flair, make DeltaBot remove this tag as soon as OP replies to a comment.

AutoModerator can auto-flair every post but can't remove them when OP replies to a comment. I was thinking, maybe DeltaBot and AutoMod could work together, like this:

AutoMod auto-flairs every post. Then, as DeltaBot scans through the comments, it comes across a comment made by an OP, so it checks whether the post still has the flair, and if it does, it removes it.

Auto-PM a user when they receive their first delta.

Here's a draft:


Congratulations; you've earned your first delta!

As you may already know, a delta (∆) is given when a comment has changed someone's view. For a more detailed explanation of the delta system, see here.

/u/DeltaBot has updated your user flair and created your own wiki page which will be updated every time you earn a delta. If you do well, you may find yourself on our leaderboards (the monthly one is also featured in our sidebar).

Good luck, and happy CMVing!


Cleaning up and Closing Issues

So I'm /u/wmcscrooge from reddit making this issue because of the post by /u/Snorrlax about the amount of issues on this project. I've spent yesterday and today looking through all the issues and noticed that there are a lot of times where the issues are stale and don't need to be open anymore. The following is a list of all the issues and what I think should be done with them.

1 - Issue #1 should probably be closed. Not because it is done or necessarily because it is useless, but it is so far down the list that I doubt very few people are actually working on it. Regardless of whether you choose to keep it or not, the information should definitely be placed on the README at least so that people know about it coming in.
3 - Issue #3 as far as I can tell was referenced incorrectly slightly giving the impression that it was fixed which was wrong. It should stay open.
4 - This is a big issue that seems to have no work done on it. It should stay open and should be added to the README.
6 - All the work for this issue seems to have been fixed with Issue #50 which was not pulled and was supposed to be added in manually. It should work fine as long as someone updates the code to work with the current version.
18 - This issue can be closed, since it was fixed by Issue #56.
22 - This issue can be closed. I went through all the formatting problems and they have been fixed.
32 - This issue seems to have been eventually scrapped because of hardness to implement because of the way reddit is designed. In addition, a probably fix has already been submitted so this issue can be closed.
35 - This issue is really just asking about whether anyone is working on the issues. It isn't actually an issue as far as I can tell and should be closed.
38 - This issue can be closed because a pull request was submitted by chilee which solves this problem.
42 - This issue is more about actually developing and formatting and should be moved to the documentation so new developers can read it. It should be closed.
47 - This issue looks like it should stay open, even though it doesn't have any recent activity. Can someone say whether this is still an issue?
48 - This issue can be closed since Travis Cl has already been implemented.
50 - This issue should be closed since it needs to be manually implemented or at least updated. Someone should start anew using this and #6 as a base.

The above list basically says that the following issues should be closed:

  1. #1
  2. #6
  3. #18
  4. #22
  5. #32
  6. #35
  7. #38
  8. #42
  9. #48
  10. #50

After this, only 3 issues will be open. I know that this will seem rather radical, but I would strongly recommend that you just go through and close all the above-listed issues unless you know for a fact that it is still a problem. Pretty much all of the 10 issues have not seen any activity in the last couple weeks. If people complain or show that it is still a problem, then you can reopen them, but I think that right now, it is just cluttering up the issues page.

I'll probably come up with a pull request soon that updates the README so that it includes all the major issues for new developers and has the information recorded in the closed issues.

Hope it helps!

Is anyone working on this at the moment?

So recently PixelOrange ran a script that cleaned up the wiki feature a bit, and we announced it to the subscribers of CMV. Now that's pretty much done, I was wondering what the next steps are? It would perhaps make sense to try and get /r/changemyview/wiki/leaderboards working, then the first-delta-PM feature can start working. Or maybe the "No OP replies yet" flair should come first, but I imagine that's a bigger job. Having said that, it would be nice if all of the features in the issue list would come soon, so there isn't any current priorities as far as I can tell. Anyway, I was just wondering if anyone was looking into them?

delta_tracker page no longer links to wiki

Sometime in the recent past, the delta_tracker page stopped linking to the user's wiki. It now links to the user's /u/ page.

Change line 328 to:

new_link = "\n\n* /u/%s -- http://www.reddit.com/r/changemyview/wiki/%s" % (parent_author, parent_author)

Getting Travis CI up and running

Since we're writing tests, we might as well put them to good use!

There's a tool called Travis CI that can build and test DeltaBot automatically every time we make a push to GitHub. If someone makes a change that breaks DeltaBot and causes a test to fail, Travis CI will catch it, and we can avoid pushing DeltaBot to production.

I've added a .travis.yml file to DeltaBot which tells Travis which tests need to be run. I've set it up so that every time I push to my fork, Travis builds and tests the code.

Next, we need someone who has push permission on this repo to sign up with Travis and flick the on switch. I'll have more info on that in a bit.

Comment history is skipping comments

DeltaBot is consistently missing deltas. I believe this to be a result of the comment history feature. I have temporarily added a feature that will automatically clear the history and perform a full scan. Once a better history has been devised, we will need to remove the auto-clear. It can be found in the go(self): function.

Improve the "delta history" wiki page feature.

A while ago we thought it would be a good idea to have individual wiki pages that list a user's delta history. A basic version of this has already been implemented (see here for an example), but it is not ready to be revealed. There are a few things that need to be done:

Properly formatted wiki pages. The layout should look something like this:

/u/user's delta history:

where the link takes you to the comment that earned the delta rather than the whole post. The number in the brackets shows the number of deltas that comment earned in total, rather than re-adding the link to the wiki page every time. The links should also be in reverse chronological order, i.e the newest delta at the top.

Links directly to a user's page from sidebar toplist. The number of deltas in the top ten leaderboard currently links to a blank page. We'd like this to link to the user's wiki page.

Account for special characters in usernames and wiki page names. For example, /u/xXx_no_scope_xXx's wiki page causes the underscores to be missed in the introduction, as two underscores can be used for italics.

Changing this:

User xXx_no_scope_xXx received deltas

to this:

/u/xXx_no_scope_xXx's delta history

fixes the problem. Can someone add that in?

Small change in the 'deltas' column of the leaderboard.

Currently, in the deltas column, it says x∆, with x being the number of deltas earned that month.

I'd like to change this so that a) the delta symbol is removed - we are already aware that it is the number of deltas due to the title, and b) it includes the total number of deltas that user has earned in brackets, to save confusion, as it currently only shows the number they have earned that month.

So instead of CurrentMonth∆, it would be CurrentMonth (Total).

Also, the 'Total' should be the only part that links to the user's wiki history page, rather than the whole x (y). I think that would be cleaner.

Wiki list ordering (Snorrrlax request)

Another small style change. It currently looks like this:

Determinism requires faith. CMV. (1)

I think Robin Thicke's Blurred Lines is rape-y and sexist. CMV (1)

Could it look like this instead:

I added another link in the first one to show what the sub-list would look like. Thoughts?

DeltaBot Requirements

I was working at trying to make deltaBot more testable, but it's becoming difficult to tell if I'm breaking features in the process.

I think DeltaBot could use a Requirements document. Nothing fancy, just a detailed list of features to help new developers figure out what things deltaBot needs to do.

I'm going to start here. Anyone familiar with the project, please chime in with anything that isn't included:

Constraints:
1 - DeltaBot cannot store anything in a database, aside from the most recently scanned comments' ID.
2 - DeltaBot should make the fewest possible calls to PRAW while still doing its job.
3 - DeltaBot should be able to stop and restart later, using the most recently scanned comment to resume where it left off. If this does not work, start from the oldest comment. We cannot assume that it is running continuously.

Features:
1 - DeltaBot should periodically scan any new comments that have been made in its subreddit.
2 - If a comment contains a Delta Symbol, DeltaBot should award 1 point to the author of the comment's parent, unless:
2.1 - The parent is OP, DeltaBot or the awarder.
2.2 - The commenter has already awarded a delta to this comment.
2.3 - The commenter has already awarded a delta to the parent's author at a higher point in the thread (but elsewhere in the comment tree or elsewhere in the submission's comment page are cool)
2.4 - The comment is shorter than [length]
3 - Awarding a delta to a user consists of:
3.1 - Adding 1 to the number in the user's flair or giving them a flair of "1" if they have no flair
3.2 - Checking if they have one of the top 10 scores this month. If so, update the high score chart in the sidebar to show this.
3.3 - If the user has their own wiki page, update it to show the correct number of deltas.
3.4 - If the user does not have a wiki page, create one with the correct number of deltas.
4 - DeltaBot should periodically scan its inbox to check for commands from mods.
4.1 - If there is a message from a mod, it scans the message for commands
4.1.1 - If it receives the command "STOP" it will save the ID of its most recently scanned comment and terminate
4.1.2 - [If it receives etc. etc. etc.]

Config variables not being passed expected number of arguments to format string.

Hi everyone, just starting to try to help with this project. I'm trying to get it working on my machine and have some issues that I am hoping someone can explain. Hopefully this is the right place to post.

In the update_leaderboard function it appears that self.config.scoreboard['table_leader_entry'] and self.config.scoreboard['table_entry'] are not being passed the correct amount of string arguments that the config file expects they have. It appears that they were passed the correct amount of arguments at one point in time but are now not being passed enough.

I am thinking maybe someone changed their config file on their machine but hasn't updated the example one to reflect these changes.

If someone could help me with this that would be great thanks!

Make the user flair of the top ten viewchangers stand out a bit.

This is partly a CSS job, as we'd have to add some code to the subreddit stylesheet, but it should be fairly simple:

Currently, all user flairs have the css class "points". For the top ten viewchangers, this would need to be changed to something else. Perhaps the number one viewchanger could be different altogether. For example:

Normal flair css class: "points".
Leaderboard numbers 10-2 css class: "points1".
Leaderboard number 1 css class: "points2".

Any random three words would do.

This should be for the top ten viewchangers of that month, not all time. Someone's legacy may live on in the all time leaderboard but it would be a better idea to pass on the "golden flair" to the most active viewchanger, in my opinion.

Also, feel free to suggest which colours to use. I was thinking numbers 10-2 could have a golden border, and number 1 would be fully golden (but not too bright).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.