Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
MECHA-206 Update Board indexes in the Data Field on initial setup, FB…
Browse files Browse the repository at this point in the history
…R and add a command to initiate a reindex manually (!index)
  • Loading branch information
Marenthyu committed Apr 9, 2017
1 parent 8c55668 commit d0f008e
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions sopel-modules/rat-board.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def setup(bot):

try:
refresh_cases(bot)
updateBoardIndexes(bot)
except ratlib.api.http.BadResponseError as ex:
warnings.warn("Failed to perform initial sync against the API")
import traceback
Expand Down Expand Up @@ -452,6 +453,24 @@ def refresh_cases(bot, rescue=None, force=False):
if case:
board.remove(case)

def updateBoardIndexes(bot):
board = bot.memory['ratbot']['board']

for rescue in board.rescues:
with board.change(rescue):
rescue.data.update({'boardIndex' : rescue.boardindex})
save_case(bot, rescue, forceFull=True)

@commands('reindex', 'updateindex', 'index', 'ri')
@require_rat('You need to be a registered and drilled Rat to execute this command!')
def cmd_reindex(bot, trigger):
"""
Updates all Indexes with the API (/Dispatch Board)
aliases: reindex, updateindex, index, ri
"""
bot.say("Updating board indexes...")
updateBoardIndexes(bot)
bot.say("Done.")

def save_case(bot, rescue, forceFull=False):
"""
Expand Down Expand Up @@ -1611,13 +1630,15 @@ def cmd_host(bot, trigger):
@require_overseer('Sorry, but you need to be a registered Overseer or higher to access this command.')
def cmd_forceRefreshBoard(bot, trigger):
"""
Forcefully resets the Board. This removes all "Ghost" Cases as they are grabbed from the API. Boardindexes will get lost and changed by this
Forcefully resets the Board. This removes all "Ghost" Cases as they are grabbed from the API. Boardindexes will get changed by , but updated on the Dispatch Board afterwards.
aliases: refreshboard, resetboard, forceresetboard, forcerefreshboard, br, fbr, boardrefresh (kinda went overBOARD with that. hah. puns.)
"""
bot.say(
'Force refreshing the Board. This removes all cases and grabs them from the API. DISPATCH, be advised: Case numbers may be changed!')
'Force refreshing the Board. This removes all cases and grabs them from the API.')
refresh_cases(bot, force=True)
bot.say('Force refresh done.')
bot.say('Reload done, trying to update indexes...')
updateBoardIndexes(bot)
bot.say("All Indexes updated, force refresh complete!")


def getFact(bot, factname, lang='en'):
Expand Down

0 comments on commit d0f008e

Please sign in to comment.